/ Published in: PHP
The following are instructions to "re-post" files that have been already been POSTed to your php script. This can help if you want to have a form (with file upload) that POSTs its data to your own script where the text elements can be handled and then the script POSTs the file for processing/storage on another system.
Basically the key is that you only POST the `$_FILES['tmp_name']` with an "@" symbol prepended.
Spent a good hour trying to figure this out. Thanks to gordon who posted on 08-Sep-2004 10:08 at http://theserverpages.com/php/manual/en/ref.curl.php
Basically the key is that you only POST the `$_FILES['tmp_name']` with an "@" symbol prepended.
Spent a good hour trying to figure this out. Thanks to gordon who posted on 08-Sep-2004 10:08 at http://theserverpages.com/php/manual/en/ref.curl.php
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?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); } } 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) { return $output; } ?>