dongtun1209 2012-12-25 22:48
浏览 18
已采纳

如何获取名称中包含iso-8859-2字符的远程映像?

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?

  • 写回答

2条回答 默认 最新

  • dsghpgmay31938863 2012-12-25 22:53
    关注

    Use urlencode() on the filename. don't urlencode() the entire url.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应