I'm building a PHP API for some software that allows file uploads. The software API given to us requires that file uploads along with form fields be posted to a remote address. I can do that with an HTML form, but I want to integrate this process into an existing server process to build a catalog of the user submitted files. So in the end I need user submitted form fields stored locally and files stored through our remote software. What I really need is a PHP function that takes a set of form fields and a file pointer and posts them. Here's an example of something similar to what I need. This come from PHP: fsockopen online documentation. <?php # $host includes host and path and filename # ex: "myserver.com/this/is/path/to/file.php" # $query is the POST query data # ex: "a=thisstring&number=46&string=thatstring # $others is any extra headers you want to send # ex: "Accept-Encoding: compress, gzip\r\n" function post($host,$query,$others=''){ $path=explode('/',$host); $host=$path[0]; unset($path[0]); $path='/'.(implode('/',$path)); $post="POST $path HTTP/1.1\r\nHost: $host\r\nContent-type: application/x-www-form-urlencoded\r\n${others}User-Agent: Mozilla 4.0\r\nContent-length: ".strlen($query)."\r\nConnection: close\r\n\r\n$query"; $h=fsockopen($host,80); fwrite($h,$post); for($a=0,$r='';!$a;){ $b=fread($h,8192); $r.=$b; $a=(($b=='')?1:0); } fclose($h); return $r; } ?> Code (markup): But this code doesn't handle multipart form data with a file upload, and I can't seem to make it work the way I need to with the file upload. Does anyone know how to do this? --Stephen
Hi Stevecrozz that is simple and easy step to upload multiple files. Check this url and read the article I think this will help you out your problem. http://www.tizag.com/phpT/fileupload.php
I can already do that. I want to first do exactly that, then run my own code to alter it on my own server, then I want that server to re-POST to a second location on a remote server that I have no control over.