I have small php app, that have some files inside. I want to send one of the files from one server to another server with using curl.
I already have file on server, I just need to send it to another server.
I execute the following code:
$url = "http://localhost:3919/";
$myCurl = curl_init();
curl_setopt($myCurl, CURLOPT_URL, $url);
curl_setopt_array($myCurl, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HEADER => false,
CURLOPT_SAFE_UPLOAD => true,
// CURLOPT_HTTPHEADER => array(
// "Content-Type: multipart/form-data"),
CURLOPT_POSTFIELDS => array(
"inputFile" => new CurlFile('@' . './Files/example.docx'))
));
$response = curl_exec($myCurl);
curl_close($myCurl);
return $response;
But it doesn't trigger the server. So what should I do wrong?
For example in other case (other app) I use this:
$file = $_FILES["inputFile"];
curl_setopt_array($myCurl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HEADER => false,
CURLOPT_SAFE_UPLOAD => true,
CURLOPT_HTTPHEADER => array(
"Content-Type: multipart/form-data"),
CURLOPT_POSTFIELDS => array(
"inputFile" => new CurlFile($file["tmp_name"], $file["type"], $file["name"]))
));
And it works perfectly.
CurlFile, you don't use the@prefix.CurlFileis a replacement for that method of sending files. You should see that in your working code you don't have that.