I had a working relationship with a Java server and a PHP server using curl from php.
Using curl I sent over an array with image data and some string vaules.
In PHP, the image was taken directly (tmp storage) from a HTTP POST form and put in the array, successfully. But now I need to move_uploaded_file first to a specified directory and read it back with fopen into another PHP document that use curl.
The only difference is that I used $_FILES[“photo”][“tmp_name”], and now I use fopen. Code:
// $image = $_FILES["photo"]["tmp_name"]; Had success with this one from FORM POST
// $filename = basename($_FILES['photo']['name']);
$filename = $_POST["filename"]; // file name from ajax post
$image = fopen('C:\\xampp\\htdocs\\app\\uploads\\'.$filename, "rw"); // the sinner?
$data = array(
'uploaded_file' => '@' . $image . ';filename=' . $filename,
);
....
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $url); // the Java web service URI
curl_setopt($c, CURLOPT_HEADER, false);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $data);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($c);
Error:
Erreur curl : couldn't open file "Resource id #3"
Array
(
[uploaded_file] => @Resource id #3;filename=480x_13197743.jpg
)
EDIT:
I printed the array from the working solution, and it points to the file/resource differently:
Array
(
[uploaded_file] => @C:\xampp\tmp\php20EA.tmp;filename=magn.png
)
Or better said, it has just a file path string. Ok, so that fixed it, using just the file path, and disregarding any copy of binary data. Answered my question =|
See the “Uploading file” example at http://php.net/manual/en/function.curl-setopt.php
Simply specify the file path in your array, not a resource handle
fopenreturns.