[英]Windows PHP cURL upload not POSTing a file
我在XAMPP 5.6.8上遇到cURL的特有問題。 使用以下代碼,我無法發送在$tempPath
指定的路徑中確實存在的文件。 我認為cURL庫可能與以c:\\
開頭的路徑混淆了。
在這里找到我的文件: 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
)
)
我認為您僅發布文件信息..實際數據未發布。 文件數據需要作為多部分發布。
要進行調試,您可能需要創建一個表單,然后在Network Tab中查看其工作方式。 它將使您可以具體查看使用瀏覽器時數據的發送方式。一旦看到,您將對如何過帳文件數據有准確的了解。
您應該查看使用curl上傳帶有文件的POST數據
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.