将$ _FILES重新发布到REST Slim Framework

My form will post all form data to a file called upload.php.

Question is: Is it possible to re-POST multipart/form-data, including $_FILES to my REST SLIM framework like this:

$headers = array('Content-type: multipart/form-data','Authorization: '.$api_key,);

$curl_post_data = array('employee_id' => $employee_id,'files' => $_FILES);
$curl = curl_init('http://[...mydomain...]/v1/uploadEquipmentDocument');

curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
curl_setopt($curl, CURLOPT_USERPWD, $api_key);

$curl_response = curl_exec($curl);

Thanks..

If you want to upload files using cUrl you can't just pass the filenames (temp/real) that you got in the $_FILES array, since this is a wrapper that PHP has to make your life easy when you want to work with files that uploaded to your server.

You got two options:

Option 1:
Use @ to tell cUrl this is not just a variable, this is a file you want to upload. In such case, php will post the file itself (and not just the string which is the name of the file):

$curl_post_data['file1'] = "@" . $_FILES['uploaded_file1']['tmp_name'];

(I assume your original form has <input type="file" name="uploaded_file1" />. use your original input names in order for this to work)

Option number 2:
If you are using PHP>=5.5 you can use the new CURLFile object, which gives you sort of the same result and a bit of a different approach:

// Create a CURLFile object
$cfile = new CURLFile($_FILES['uploaded_file1']['tmp_name'], $_FILES['uploaded_file1']['type'], $_FILES['uploaded_file1']['name']);

// Assign POST data
$curl_post_data = array('file1' => $cfile);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);

// Execute the handle
curl_exec($curl);