When the browser is uploading a file the server, it send an HTTP POST requests, that contains the file's content.
You'll have te replicate that.
With PHP, the simplest (or, at least, most used) solution is probably to work with curl.
If you take a look at the list of options you can set with curl_setopt
, you'll see this one : CURLOPT_POSTFIELDS
(quoting) :
The full data to post in a HTTP "POST"
operation.
To post a file,
prepend a filename with @ and use the
full path.
This can either be
passed as a urlencoded string like
'para1=val1¶2=val2&...' or as an
array with the field name as key and
field data as value.
If value is
an array, the Content-Type header will
be set to multipart/form-data.
Not tested, but I suppose that something like this should do the trick -- or, at least, help you get started :
$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_setpopt($ch, CURLOPT_POSTFIELDS, array(
'file' => '@/..../file.jpg', // you'll have to change the name, here, I suppose
// some other fields ?
));
$result = curl_exec($ch);
curl_close($ch);
Basically, you :
- are using curl
- have to set the destination URL
- indicate you want
curl_exec
to return the result, and not output it
- are using
POST
, and not GET
- are posting some data, including a file -- note the
@
before the file's path.