在 Windows 上使用 CURL、PHP 和 Apache 上传文件时出现问题
我在使用 CURL 和 PHP 上传文件时遇到问题(在 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" }
Edit #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 没有获取它,这是他们需要回答的问题:)
I'm having issues uploading files using CURL with PHP (on Windows - if it matters).
Basically, I can post to the URL and display what has been posted except for the field with the file. In this case, I'm testing code that points to the same server, but once I can confirm that the file gets uploaded, I will send to another domain (again, if it matters).
Here is 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);
Then, upload.php
print_r($_POST);
The result of the CURL call, the output of $buffer:
array(1) { ["boo"]=> string(5) "yaaah" }
Edit #1
Instead, I did an print_r($_FILES) and got this:
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) } }
This proves that my file is being uploaded. Why it isn't being picked up by the API I'm trying to access is a question for them to answer :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想获取有关上传文件的信息,
则没有帮助。您可能需要查看
$_FILES
以及:
这是包含有关文件上传信息的变量。请阅读有关上传文件的手册。
If you want to get information about uploaded files,
is not helpful. You might want to look into
$_FILES
as well:That is the variable that contains information about the file uploads. Please read the manual about uploading files.