簡體   English   中英

在Windows上使用CURL,PHP和Apache上載文件問題

[英]Issue uploading file with CURL, PHP and Apache on Windows

我在使用PHP的CURL上載文件時遇到問題(在Windows上,如果有關系)。

基本上,我可以將其發布到URL上,並顯示已發布的內容(帶有文件的字段除外)。 在這種情況下,我正在測試指向同一台服務器的代碼,但是一旦可以確認文件已上傳,我將發送到另一個域(同樣重要)。

這是start.php

$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_USERPWD, "user:pass");
curl_setopt($curl_handle,CURLOPT_URL, "http://domain/upload.php");
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl_handle,CURLOPT_POST, 1);
$post = array("boo"=>"yaaah",
        "xml"=>"@e:/path/to/file/new.xml");
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $post);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);

然后,upload.php

print_r($_POST);

CURL調用的結果,$ buffer的輸出:

array(1) { ["boo"]=> string(5) "yaaah" }

編輯#1

相反,我做了一個print_r($ _ FILES)並得到了這個:

array(1) { ["xml"]=> array(5) { ["name"]=> string(7) "new.xml" ["type"]=> string(24) "application/octet-stream" ["tmp_name"]=> string(26) "C:\WINDOWS\TEMP\php892.tmp" ["error"]=> int(0) ["size"]=> int(3733) } }

這證明我的文件正在上傳。 為什么我嘗試訪問的API不能提取它,這是他們要回答的一個問題:)

如果您想獲取有關上傳文件的信息,

print_r($_POST);

沒有幫助。 您可能還需要研究$_FILES

print_r($_FILES);

這是包含有關文件上傳信息的變量。 閱讀有關上傳文件的手冊

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM