【问题标题】:Issue uploading file with CURL, PHP and Apache on Windows在 Windows 上使用 CURL、PHP 和 Apache 上传文件问题
【发布时间】:2011-10-04 17:27:47
【问题描述】:

我在使用 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);

然后,上传.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 没有接收到它是他们要回答的问题:)

【问题讨论】:

  • 发生了什么或没有发生什么? curl_error() 在说什么?
  • @Pekka 没有错误。获取 HTTP 代码 202。我在查找文件时没有使用正确的范围。现在一切都很好:)

标签: php curl


【解决方案1】:

如果您想获取有关上传文件的信息,

print_r($_POST);

没有帮助。您可能还想查看$_FILES

print_r($_FILES);

这是包含有关文件上传信息的变量。请read the manual about uploading files

【讨论】:

  • 感谢您指出这一点。它向我提供了文件确实正在通过的确认。
猜你喜欢
  • 1970-01-01
  • 2013-03-15
  • 1970-01-01
  • 2017-08-01
  • 2015-04-22
  • 1970-01-01
  • 1970-01-01
  • 2017-01-23
  • 1970-01-01
相关资源
最近更新 更多