note 126976 added to function.file-exists
| From: | SteveGS at main dot php dot net | Date: | Fri, 08 Apr 2022 09:04:42 +0000 |
| Subject: | note 126976 added to function.file-exists | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-218138@lists.php.net to get a copy of this message | ||
Wordpress always prepends the full URL to any file it stores in its database so, as noted elsewhere,
file_exists() can't find the file since it uses the 'document root', not the URL. An
easy way out of this is to use:
file_exists (str_replace (home_url(), $_SERVER['DOCUMENT_ROOT'], $file) )
to check if file $file exists. Note: As from PHP8, 'DOCUMENT_ROOT' must be enclosed
within SQUARE BRACKETS, not braces as suggested by ferodano at gmail dot com
Or, if not using WP, replace home_url() above with the absolute URL name, eg. 'https://mywebsite.com' - within quotes and no trailing
foreslash.
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.135 (proxied: 92.11.167.236)
----
Manual Page -- https://php.net/manual/en/function.file-exists.php
Edit -- https://main.php.net/note/edit/126976
Del: integrated -- https://main.php.net/note/delete/126976/integrated
Del: useless -- https://main.php.net/note/delete/126976/useless
Del: bad code -- https://main.php.net/note/delete/126976/bad+code
Del: spam -- https://main.php.net/note/delete/126976/spam
Del: non-english -- https://main.php.net/note/delete/126976/non-english
Del: in docs -- https://main.php.net/note/delete/126976/in+docs
Del: other reasons-- https://main.php.net/note/delete/126976
Reject -- https://main.php.net/note/reject/126976
Search -- https://main.php.net/manage/user-notes.php