简体   繁体   English

在Windows上使用CURL,PHP和Apache上载文件问题

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

I'm having issues uploading files using CURL with PHP (on Windows - if it matters). 我在使用PHP的CURL上载文件时遇到问题(在Windows上,如果有关系)。

Basically, I can post to the URL and display what has been posted except for the field with the file. 基本上,我可以将其发布到URL上,并显示已发布的内容(带有文件的字段除外)。 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 这是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 然后,upload.php

print_r($_POST);

The result of the CURL call, the output of $buffer: CURL调用的结果,$ buffer的输出:

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

Edit #1 编辑#1

Instead, I did an print_r($_FILES) and got this: 相反,我做了一个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) } }

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 :) 为什么我尝试访问的API不能提取它,这是他们要回答的一个问题:)

If you want to get information about uploaded files, 如果您想获取有关上传文件的信息,

print_r($_POST);

is not helpful. 没有帮助。 You might want to look into $_FILES as well: 您可能还需要研究$_FILES

print_r($_FILES);

That is the variable that contains information about the file uploads. 这是包含有关文件上传信息的变量。 Please read the manual about uploading files . 阅读有关上传文件的手册

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM