开发者

Issue uploading file with CURL, PHP and Apache on Windows

开发者 https://www.devze.com 2023-04-10 09:12 出处:网络
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 cas

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 开发者_如何学Gothis:

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 :)


If you want to get information about uploaded files,

print_r($_POST);

is not helpful. You might want to look into $_FILES as well:

print_r($_FILES);

That is the variable that contains information about the file uploads. Please read the manual about uploading files.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号