[英]Uploading files to Imageshack API using HTML form, cURL and PHP
[英]Uploading file with PHP to imageshack using cURL
我正在嘗試使用以下腳本將文件上傳到imageshack:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://post.imageshack.us/');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_POST, true);
$post = array(
'fileupload'=> '@../../resources/images/cancel.png',
'optsize' => 'resample',
'rembar' => '1'
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
但是,我從imageshack得到以下錯誤:
Wrong file type detected for file cancel.png:application/octet-stream
。
為什么,以及如何解決? 提前致謝!
編輯:當我使用JPG或GIF(甚至是動畫的,雖然Imageshack然后去動畫它們,我認為僅使用第一幀)時它確實有效,但不是使用PNG。
編輯2:我發現了如何解決它。 如前所述,它只接受JPG和GIF。 因此,我獲取需要上傳的圖像的位置,將其復制到結尾為.jpg
的臨時位置,上傳文件,然后在完成后,從臨時位置刪除該文件。
將Content-type設置為文件類型。
根據手冊,它必須是一個數組或對象。 所以在這里
$arr = array('Content-type: text/plain') ;
curl_setopt ( $ch , CURL_HTTPHEADER , $arr );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.