Php upload image to remote server with cURL
<p>I would like to use cURL in php to upload an image to a remote image server. I have this piece of code, it's on the webserver:</p>

<pre><code>&lt;form enctype="multipart/form-data" encoding="multipart/form-data" method="post" action="webform.php"&gt;
&lt;input name="somevar" type=hidden value='.$somevar.'&gt;
&lt;input name="uploadfile" type="file" value="choose"&gt;
&lt;input type="submit" value="Upload"&gt;
&lt;/form&gt;
</code></pre>

<p>and:</p>

<pre><code>if (isset($_FILES['uploadfile']) ) {

 $filename  = $_FILES['uploadfile']['tmp_name'];
 $handle    = fopen($filename, "r");
 $data      = fread($handle, filesize($filename));
 $POST_DATA = array(
   'somevar' =&gt; $somevar,
   'uploadfile' =&gt; $data
 );
 $curl = curl_init();
 curl_setopt($curl, CURLOPT_URL, 'http://1.1.1.1/receiver.php');
 curl_setopt($curl, CURLOPT_TIMEOUT, 30);
 curl_setopt($curl, CURLOPT_POST, 1);
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($curl, CURLOPT_POSTFIELDS, $POST_DATA);
 $response = curl_exec($curl);
 curl_close ($curl);
 echo $response;

}
</code></pre>

<p>On the image server I've got an image upload handling php file, which worked very well on localhost, but I would like to use it on the remote server. This is how I handled the uploaded image file in the receiver.php:</p>

<pre><code>move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)
</code></pre>

<p>I want to directly pass the image file to the remote server script, so this way I don't need to rewrite the whole upload script. I tried to post the image name, type, size as post variables, but I haven't got the ['tmp_name'] since it's not on localhost.</p>

<p>How can I solve this? Thank you guys for any help!</p>