- Description: i have a file test.zip at here: http://host_1.com/test.zip - I have a php host at here: http://host_2.com - And i need a php code put in host_2.com to upload file test.zip to http://host_3.com/upload_process.php - upload_process.php is php file, it process file upload (HTTP POST) - With some knowledge about php, i think use fsockopen, read file test.zip at http://host_1.com/test.zip, send some header, and send it to http://host_3.com/upload_process.php as same as when use html form post to upload file normally - But i don't know in detail how to do it? - Can anyone help me? - Thanks.
You can use cURL. http://www.php.net/curl If both hosts are yours, I'd recommend using FTP though. http://www.php.net/ftp
- I found a way to upload file, but it only do well with local file: $post_data = array(); //$post_data['file'] = "http://mirror2.internetdownloadmanager.com/idman509.exe"; $post_data['file'] = "@test.zip"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://host.com/upload_process.php" ); curl_setopt($ch, CURLOPT_POST, 1 ); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $postResult = curl_exec($ch); if (curl_errno($ch)) { print curl_error($ch); } curl_close($ch); print "$postResult"; Code (markup): - I have a idea is transfer file need upload to host and upload load it as local file, but seem it waste a lot of bw. - any suggestion? Thanks
You can do: 1. Create a finction like this: function url_copy($source) { $d=explode("/",$source); $dest=$d[count($d)-1]; $f1=fopen($source,"rb"); $f2=fopen($dest,"w"); echo "<SCRIPT>window.status='Copying \'$source\' to \'$dest\'...';</SCRIPT>\n"; flush(); while ($buff=fread($f1,1024)) fwrite($f2,$buff); fclose($f1); fclose($f2); $size=filesize($dest); echo "<SCRIPT>window.status='$size bytes copied.';</SCRIPT>\n"; } PHP: 2. And do as you wish!