I'm saving and resizing tons of images from a remote server using cURL in PHP, but the previous developer doesn't implemented any kind of system for make the user uploaded pictures "safe", so the users were able to upload any kind of file format with any kind of name then the uploaded files name is saved to a database as is, so lots of files have non URL safe and iso-8859-8 characters. For example:
gaght101125659_5 Gn-eŐs mtó gÁrlós.jpg
According to this answer I made a code for getting the pictures.
private function getRemoteUrl($file)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $file);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$img = imagecreatefromstring($this->getRemoteUrl($url));//$url contains the plain url of the image.
This code works perfectly for images with a name like gaht123115516_2.jpg
but for the example shown above it gives an error saying:
Warning: imagecreatefromstring() [function.imagecreatefromstring]: Data is not in a recognized format in /home/test/public_html/resizing.php on line 64
Of course, because of the fancy characters. So what should I do in getRemoteUrl($file)
with the $file
variable to make it work? Can this be done in PHP? If not what other methods/programming languages should I try?