<?php
$url = ''; // the url of the file processing script (ie, http://example.com/upload)
// Iterate through each file, check it has been stored in a tmp location, then post to another url
foreach ($_FILES as $file) {
// tmp_name will look something like this /private/var/tmp/phpRDJDT92
if ($file['tmp_name'] > '') {
$params['file'] = '@'.$file['tmp_name']; // Its this @ symbol thats the key.
$response = post($url, $params);
}
}
function post($url, $params = array()) {
try {
$response = http_post($url, $params);
return $response;
} catch (Exception $e) {
return null;
}
}
// More REST methods available at http://snipplr.com/view/19781/php-rest/
// Nothing special about this cURL POST. You dont have to set any special headers for file uploading.
function http_post($url, $data) {
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $data);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($c);
curl_close($c);
return $output;
}
?>