1

I am sending post API request to external server with a PDF file from my laravel app files folder which is under my public folder inside Laravel app folder. i am sending PDF file from this folder and getting. file not found error can someone help.

$samplefile = "/var/www/html/laravel_project/public/1476505004.pdf";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://api_upload_usl/api/uploads");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,array('myFile'=>"@$samplefile",'token'=>$token,'id'=>1));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postResult = curl_exec($ch);
curl_close($ch);
Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
Priyank lohan
  • 483
  • 1
  • 6
  • 17

1 Answers1

0

I'm not intamatley familiar with the way you're meant to upload files using curl, but as per this answer,

Also, could you elaborate on file not found error? Are you sure that's a PHP error? Could it be the webserver telling you that the page you're requesting doesn't exist?

You also didn't specify the curl as a post, maybe it's doing a different operation than the endpoint expects

EG:

if (function_exists('curl_file_create')) { // php 5.6+
  $cFile = curl_file_create($file_name_with_full_path);
} else { // 
  $cFile = '@' . realpath($file_name_with_full_path);
}
$post = array('extra_info' => '123456','file_contents'=> $cFile);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec ($ch);
curl_close ($ch);
Community
  • 1
  • 1
Zachary Craig
  • 2,192
  • 4
  • 23
  • 34
  • i want to send a file from one server to another. the other server on which i am sending file require file as a object as form data. – Priyank lohan Oct 27 '16 at 05:38