I have a image with the name The-seven-Churches-of-the-Revelation-&-Istanbul.jpg
However, the filename is saved in the database in this format; The-seven-Churches-of-the-Revelation-%26-Istanbul.jpg
I am using the following code, and also ignoring space
$cover = str_replace('%20', ' ', $cover);
if (!\Illuminate\Support\Facades\File::exists(base_path($cover))) :
echo "file not found";
endif;
Result is
file not found
How can I deal with the special characters in the filenames?
It seems you may be having issues with the URL Encoded values, so urldecode
may be your friend. You can see the docs for this here
$cover = urldecode($cover);
if (!\Illuminate\Support\Facades\File::exists(base_path($cover))) :
echo "file not found";
endif