- Or, in the same approach you can encode /decode the file name with base64:
1. When uploading the file, apply
base64_encode() to name (without extension).
Code: Select all
$name ='نور صلح';
$ext ='jpg';
$fname = base64_encode($name) .'.'. $ext; //filename, base64 and extension
echo $fname; // 2YbZiNixINi12YTYrQ==.jpg
2. When fetching the file from server, apply
base64_decode() to the filename (after extracting the extension) to get the correct name.
Code: Select all
$filename ='2YbZiNixINi12YTYrQ==.jpg'; //name encoded with base64, and its extension
$name_ext = explode('.', $filename, 2); //array with [name, extension]
$name = base64_decode($name_ext[0]) .'.'. $name_ext[1]; //decode the name only
echo $name; // نور صلح.jpg
3. In URL /SRC address add the filename as it is on server.
Code: Select all
$filename ='2YbZiNixINi12YTYrQ==.jpg'; //name encoded with base64, and its extension
$name_ext = explode('.', $filename, 2); //array with [name, extension]
$name = base64_decode($name_ext[0]); //decode the name only
echo '<a href="'. $dir. $filename .'">'. $name .'</a>';
echo '<img src="'. $dir. $filename .'" alt="'. $name .'" />';