我的圖片上傳使用下面的代碼ENCTYPE捲曲PHP
<form target="my_iframe" action="http://imagezilla.net/api.php" method="post" enctype="multipart/form-data">
<input type="file" name="file" accept="image/x-png, image/gif, image/jpeg" />
<input type="hidden" name="apikey" value="" />
<input type="hidden" name="testmode" value="1" />
<input type="submit" value="Upload Image" />
</form>
這工作很好,但我沒有得到結果返回由於跨域規則的方式來imagezilla.net,所以我試圖把它變成捲曲PHP
<?php
$ch = curl_init("http://imagezilla.net/api.php?file='C:\Anti-Backlash-Nut.jpg'&apikey=''&testmode=1");
$header = array('Content-Type: multipart/form-data');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
?>
(第二批的代碼已經只是封閉的快速測試文件)
我不能在PHP代碼的MIME類型工作正確(行$ header = ...),因爲它只是沒有文件上傳。我究竟做錯了什麼?
我不得不將CURLOPT_HTTPHEADER,$標題更改爲CURLOPT_HEADER, 0,因爲它回來了一個錯誤,但現在當其成功輸出爲空時,如果有問題,則顯示結果 – user170324
@ user170324這可能是因爲api可能不會返回任何成功上傳 – alwaysLearn
當我使用表單方法時,它會返回圖像的服務器文件路徑,但它確實將它作爲xml返回,是否需要將標題更改回httpheader並將內容類型添加到xml? – user170324