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
)

)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s