2015-06-23 117 views
1

我在XAMPP 5.6.8上遇到了一個特殊的cURL問題。使用下面的代碼,我無法發送在$tempPath中指定的路徑中存在的文件。我在想,cURL圖書館可能會與我的路徑相混淆,該路徑始於c:\Windows PHP cURL上傳不在POST文件

我的文件在這裏找到:C:\tempFolder\r_4878.tmp

在Linux服務器上,使用完全相同的代碼,這確實使用/mnt/temp/工作。爲什麼應該有差異?

什麼可能在這裏打破?

上傳代碼

$post = array('file_name' => $reportID, 'file_contents'=>'@'.$tempPath.''); 

$return = true; 

# set the url that we need to use to upload to each server 
$url = "http://server.corp/uploadServer.php"; 

# curl the file to the remote server 
$ch = curl_init($url); 
curl_setopt($ch, CURLOPT_POST,    true ); 
curl_setopt($ch, CURLOPT_HEADER,   false ); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true ); 
curl_setopt($ch, CURLOPT_TIMEOUT,   240 ); 
curl_setopt($ch, CURLOPT_POSTFIELDS,  $post ); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json')); 

# get the servers respone and decode the json response 
$result = json_decode(curl_exec($ch)); 

$t = array($url, $tempPath, file_exists($tempPath), $result->success, $post, $result); 

echo "\r\n".print_r($t, true)."\r\n\r\n"; 

curl_close($ch); 

遠程服務器

$output['file_exists'] = file_exists($_FILES["file_contents"]["tmp_name"]); 
$output['file_path'] = $fileName.".txt"; 
$output['tmp_name'] = $_FILES["file_contents"]["tmp_name"]; 
$output['success'] = move_uploaded_file($_FILES["file_contents"]["tmp_name"], $fileName.".txt"); 

響應

Array 
(
    [0] => http://server.corp/uploadServer.php 
    [1] => C:\tempFolder\r_4878.tmp 
    [2] => 1 
    [3] => 
    [4] => Array 
     (
      [file_name] => UnitTest25-felix 
      [file_contents] => @C:\tempFolder\r_4878.tmp 
     ) 

    [5] => stdClass Object 
     (
      [file_name] => UnitTest25-felix 
      [file_exists] => 
      [file_path] => UnitTest25-felix.txt 
      [tmp_name] => 
      [success] => 
      [generationTime] => 9.70363616943E-5 
     ) 

) 
+0

做$ _FILES一個的var_dump看什麼服務器接收如果有什麼? – MiltoxBeyond

+0

它在響應中 – pcnate

+0

這是您的響應,而不是$ _FILES數組的實際值。也許它將數據作爲不同的/臨時名稱發送。或者它可能發送不正確。你可以做'$ output ['files'] = json_encode($ _ FILES);' – MiltoxBeyond

回答

2

我想你是唯一的後ing文件信息..實際數據不發佈。文件數據需要作爲多部分發布。

要進行調試,您可能需要創建一個表單並查看網絡選項卡中的工作方式。它將允許您在使用瀏覽器時專門查看數據的發送方式。 一旦看到您將對如何POST文件數據有準確的想法。

你應該看看Using curl to upload POST data with files

+0

中完全正常工作,我忘了提及。這在Linux中的apache中工作 – pcnate

+0

你的客戶端代碼[問題出在哪裏],I-e curl調用的代碼與apache無關。 – Scalable

+1

除在apache/linux vs xampp/windows上執行php。我沒有用瀏覽器上傳 – pcnate