php - File upload using curl is not working -
i trying upload file using curl in symfony uploading not working, code given below.
public function filepassingaction(request $request, $guid) { $ch = curl_init(); curl_setopt($ch, curlopt_url, "http://192.168.0.41/lis/web/app_dev.php/interface/file-upload"); curl_setopt($ch, curlopt_header, false); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_post, true); curl_setopt($ch, curlopt_postfields, array( 'file' => '@'.$this->getparameter('directory1').'/file.pdf', )); $result = curl_exec($ch); curl_close($ch); ($result); return new jsonresponse($result); }
receiving action
public function fileuploadaction(request $request) { $file = $request->files->get('file'); // generate unique name file before saving $filename = md5(uniqid()) . '.' . $file->guessextension(); // move file directory brochures stored $file->move( $this->getparameter('directory2'), $filename ); return new jsonresponse(); }
in service.yml
directory1: '%kernel.root_dir%/../web/uploads/directory1' directory2: '%kernel.root_dir%/../web/uploads/directory2'
use
realpath
$file_name_with_full_path = $this->getparameter('directory1').'/file.pdf'; curl_setopt($ch, curlopt_postfields, array( 'file' => '@'.realpath($file_name_with_full_path), ));
for php 5.5+
$file_name_with_full_path = $this->getparameter('directory1').'/file.pdf'; curl_setopt($ch, curlopt_postfields, array( 'file' => curl_file_create($file_name_with_full_path), ));
Comments
Post a Comment