My Title indicates what I most want this article to be found for, but this script does so much more.
I searched long and hard with that as a search phrase, and only found others asking how to do it. If you find this information helpful, the best thanks you can give me is a PR passing linkback.

As far as I can tell, this will handle all GET and POST form requests as well as dynamic page requests (because they are just like GET requests). It should handle any number of uploaded files. I forsee a problem on a busy server or popular website where multiple users with the same filename could be attempting to upload at the same time. This is easy enough to fix, I just haven't done it yet. I point out here, as well as inline, the "allowed_file" function is a stand in, and really should be replaced with actual upload security tests.


$url=''.$qs; //This allows the same block of code to handle GET requests

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);

if($_POST){ // I found some handlers choke if you post an empty $_POST array, so I put it in a conditional.
foreach($_FILES as $userfile=>$file){
if (allowed_file(${$userfile})){
//The next lines are what gave me the most trouble, along with getting everything into one array.
//The file needs to be on your server with a real name, not a temp name. Most handlers will require an extension which is lost with tmp_name
//The at "@" below tells cURL that it needs to send the contents of a file, not the text of the path.
// replace home/acctname/tempimages with a path to a folder on your server, chmod 777

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_vars);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIE,$newcookies);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);

// if files were written to our tempimages directory, discard them.
if ($marker)
foreach($_FILES as $userfile=>$file)
if(file_exists('/home/acctname/tempimages'.${$userfile}) && !is_dir('/home/acctname/tempimages'.${$userfile}))
// process and echo $data as needed.

function allowed_file($filename) //this needs to be fleshed out, but it`s a start.
if($filename){return TRUE;}else{return FALSE;} // be sure to replace this with some decent security.

Discliaimer: This is provided with no guarantee that I haven't really screwed it up somewhere.