Tag: Send file

Sending files using cURL in PHP

index.php

$target_url = ‘http://example.com/post.php ‘;
$file_name_with_full_path = “C:/xampp/htdocs/demo/1.jpg”; //full path of your file

$ch = curl_init();
$args[‘files’] = new CURLFile($file_name_with_full_path);

curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result=curl_exec ($ch);
curl_close ($ch);

Post.php

Array
(
[files] => Array
(
[name] => 1.jpg
[type] => application/octet-stream
[tmp_name] => C:\xampp\tmp\php4565.tmp
[error] => 0
[size] => 158530
)

)