我已經在C#中被賦予此代碼示例UploadFile C#替代
var fileUploadClient = new WebClient();
fileUploadClient.Headers.Add("Content-Type", "application/xml");
var rawResponse = fileUploadClient.UploadFile(Url, FilePath);
我想用複製這個在PHP:
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, "http://api.dev/import");
curl_setopt($handle, CURLOPT_HTTPHEADER, array(
'Content-Type: application/xml',
'Authorization: api '.$this->token
));
curl_setopt($handle, CURLOPT_HEADER, true);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_VERBOSE, true);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, array('file' => new \CurlFile('/tmp/import.xml', 'application/xml', 'import.xml')));
$response = curl_exec($handle);
$code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
但是好像這是不相同到C#示例,因爲我收到了內部服務器錯誤消息。有人知道不同之處嗎?
目錄權限? – Maximus2012