我正在尝试使用以下脚本将文件上传到 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
的临时位置,上传文件,然后在完成后从临时位置删除文件。