tags:

views:

101

answers:

3

It's trivial to get image from server but I think about something different. It is crazy question but... Is it possible to send file (image) to a server but not using form upload or ftp connection? I want to send a request to eg. http://www.example.com/file.php with binary content. I think I need to set Content-type header image/jpeg but how to add some content to my request?

+1  A: 
VolkerK
+1  A: 

there are multiple ways to use curl to upload image files, e.g.:

$ch = curl_init();
$data = array('name' => 'Foo', 'file' => '@/path/to/image.jpeg');
curl_setopt($ch, CURLOPT_URL, 'http://localhost/upload.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);

you can check the examples at: http://au.php.net/manual/en/function.curl-setopt.php

Andy Lin
+1  A: 

VolkerK is completely right but my experience suggest that sending a file "@" operator will only work with arrays.

$post['file'] = "@FILE_Path"

Now you can send the file using CURLOPT_POSTFIELDS

Shubham