Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>When the browser is uploading a file to the server, it sends an HTTP POST request, that contains the file's content.</p> <p>You'll have te replicate that.</p> <p><br> With PHP, the simplest <em>(or, at least, most used)</em> solution is probably to work with <a href="http://fr2.php.net/curl" rel="nofollow noreferrer"><strong><code>curl</code></strong></a>.</p> <p>If you take a look at the list of options you can set with <a href="http://fr2.php.net/curl_setopt" rel="nofollow noreferrer"><strong><code>curl_setopt</code></strong></a>, you'll see this one : <strong><code>CURLOPT_POSTFIELDS</code></strong> <em>(quoting)</em> :</p> <blockquote> <p>The full data to post in a HTTP "POST" operation. <br><strong>To post a file, prepend a filename with @ and use the full path</strong>. <br>This can either be passed as a urlencoded string like 'para1=val1&amp;para2=val2&amp;...' or as an array with the field name as key and field data as value. <br>If value is an array, the Content-Type header will be set to multipart/form-data.</p> </blockquote> <p><br> Not tested, but I suppose that something like this should do the trick -- or, at least, help you get started :</p> <pre><code>$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://www.example.com/your-destination-script.php"); 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' =&gt; '@/..../file.jpg', // you'll have to change the name, here, I suppose // some other fields ? )); $result = curl_exec($ch); curl_close($ch); </code></pre> <p>Basically, you :</p> <ul> <li>are using curl</li> <li>have to set the destination URL</li> <li>indicate you want <code>curl_exec</code> to return the result, and not output it</li> <li>are using <code>POST</code>, and not <code>GET</code></li> <li>are posting some data, including a file -- note the <code>@</code> before the file's path.</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload