dpevsxjn809817 2016-10-30 14:50
浏览 31
已采纳

无法使用php下载图像(错误请求)

iam trying to download image from an url, tried multiple methods (almost every method i found on google) but not yet succeeded, Some solutions gives error

Found Document has been moved here

and most solutions gives error

file_get_content: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request

One of the solutions i'v tried so far (there are more than 25 i have tried)

$fp = fopen ('mydirectory/image.jpg', 'w+');              // open file handle

$ch = curl_init('https://www.otakusmash.com/read-manga/mangas/AIKI/008/Aiki_v02_c08_000.jpg');
            // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // enable if you want
curl_setopt($ch, CURLOPT_FILE, $fp);          // output to file
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1000);      // some large value to allow curl to run for a long time
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0');
curl_setopt($ch, CURLOPT_VERBOSE, true);   // Enable this line to see debug prints
curl_exec($ch);
curl_close($ch);                              // closing curl handle
fclose($fp);

Please help me out

  • 写回答

1条回答 默认 最新

  • douzhi9635 2016-10-30 15:45
    关注

    You have a error in your code, Please use below code

    $fp = fopen ("mydirectory/image.jpg", 'w+');              // open file handle
    
    $ch = curl_init('https://www.otakusmash.com/read-manga/mangas/AIKI/008/Aiki_v02_c08_000.jpg');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // enable if you want
    curl_setopt($ch, CURLOPT_FILE, $fp);          // output to file
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 1000);      // some large value to allow curl to run for a long time
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0');
    curl_setopt($ch, CURLOPT_VERBOSE, true);   // Enable this line to see debug prints
    curl_exec($ch);
    curl_close($ch);                              // closing curl handle
    fclose($fp);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!