ThunderAI Posted June 9, 2008 Share Posted June 9, 2008 There is a server that updates a known file every day. How do I program PHP using header() or another function to go to this website, download the file and place it in a folder for another script to conduct work on it. From what I can see an read about header() that doesn't seem to be able to do what I am looking for. Is this type of request even possible? Link to comment https://forums.phpfreaks.com/topic/109447-solved-force-download-of-a-remote-file-on-another-server-possible/ Share on other sites More sharing options...
jonsjava Posted June 9, 2008 Share Posted June 9, 2008 prolly a simpler answer, but here's mine: <?php $file = "example.zip"; //the file name $remote_url = "http://example/"; //the server address (minus the file name) $local_dir = "/home/user/script/"; //the directory you want the file saved to (absolute path) /* STOP EDIT */ $full_file = $local_dir.$file; $command = "/usr/bin/wget $file --output-document=$full_file"; shell_exec($command); ?> change $file, $remote_url, and $local_dir, and it will save the file to your desired folder. Next, add it to a cron (ask if you need help w/ that), and it can do it for you automatically. Link to comment https://forums.phpfreaks.com/topic/109447-solved-force-download-of-a-remote-file-on-another-server-possible/#findComment-561399 Share on other sites More sharing options...
ThunderAI Posted June 9, 2008 Author Share Posted June 9, 2008 Im going to need help with Cron, cause i dont even know what that it. Link to comment https://forums.phpfreaks.com/topic/109447-solved-force-download-of-a-remote-file-on-another-server-possible/#findComment-561406 Share on other sites More sharing options...
ThunderAI Posted June 9, 2008 Author Share Posted June 9, 2008 prolly a simpler answer, but here's mine: <?php $file = "example.zip"; //the file name $remote_url = "http://example/"; //the server address (minus the file name) $local_dir = "/home/user/script/"; //the directory you want the file saved to (absolute path) /* STOP EDIT */ $full_file = $local_dir.$file; $command = "/usr/bin/wget $file --output-document=$full_file"; shell_exec($command); ?> I tried to execute this on my own localhost to a server i also run, and it wont copy the file and wont give an error either change $file, $remote_url, and $local_dir, and it will save the file to your desired folder. Next, add it to a cron (ask if you need help w/ that), and it can do it for you automatically. Link to comment https://forums.phpfreaks.com/topic/109447-solved-force-download-of-a-remote-file-on-another-server-possible/#findComment-561422 Share on other sites More sharing options...
jonsjava Posted June 9, 2008 Share Posted June 9, 2008 Is your server windows, or Linux? Link to comment https://forums.phpfreaks.com/topic/109447-solved-force-download-of-a-remote-file-on-another-server-possible/#findComment-561440 Share on other sites More sharing options...
DarkWater Posted June 9, 2008 Share Posted June 9, 2008 You can use file_get_contents(). Link to comment https://forums.phpfreaks.com/topic/109447-solved-force-download-of-a-remote-file-on-another-server-possible/#findComment-561442 Share on other sites More sharing options...
jonsjava Posted June 9, 2008 Share Posted June 9, 2008 I'm too much of a linux admin. file_get_contents is much better. Link to comment https://forums.phpfreaks.com/topic/109447-solved-force-download-of-a-remote-file-on-another-server-possible/#findComment-561457 Share on other sites More sharing options...
DarkWater Posted June 9, 2008 Share Posted June 9, 2008 I'm too much of a linux admin. file_get_contents is much better. Lol, I love wget. Just not when writing PHP. Link to comment https://forums.phpfreaks.com/topic/109447-solved-force-download-of-a-remote-file-on-another-server-possible/#findComment-561462 Share on other sites More sharing options...
ThunderAI Posted June 9, 2008 Author Share Posted June 9, 2008 Is your server windows, or Linux? The server is on a xampp install for development on a windows machine. Link to comment https://forums.phpfreaks.com/topic/109447-solved-force-download-of-a-remote-file-on-another-server-possible/#findComment-561509 Share on other sites More sharing options...
DarkWater Posted June 9, 2008 Share Posted June 9, 2008 Lol, Windows. =/ You might want to consider getting a Linux server. Link to comment https://forums.phpfreaks.com/topic/109447-solved-force-download-of-a-remote-file-on-another-server-possible/#findComment-561514 Share on other sites More sharing options...
jonsjava Posted June 9, 2008 Share Posted June 9, 2008 <?php $file = "file.ext"; //the file name $remote_url = "http://example.com/"; //the server address (minus the file name) $local_dir = "c:/xampp/htdocs/your_folder"; //the directory you want the file saved to (absolute path) /* STOP EDIT */ $full_file = $local_dir.$file; $dl_file = file_get_contents($remote_url.$file); print $dl_file; $fh = fopen($full_file, "w+"); fwrite($fh, $dl_file); fclose($fh); ?> this should fix you up. Link to comment https://forums.phpfreaks.com/topic/109447-solved-force-download-of-a-remote-file-on-another-server-possible/#findComment-561517 Share on other sites More sharing options...
DarkWater Posted June 9, 2008 Share Posted June 9, 2008 @jons_java: He can just file_put_contents instead of the whole fopen routine. Link to comment https://forums.phpfreaks.com/topic/109447-solved-force-download-of-a-remote-file-on-another-server-possible/#findComment-561520 Share on other sites More sharing options...
jonsjava Posted June 9, 2008 Share Posted June 9, 2008 @jons_java: He can just file_put_contents instead of the whole fopen routine. *grumble grumble* You just take all the fun out of programming! *lol* Link to comment https://forums.phpfreaks.com/topic/109447-solved-force-download-of-a-remote-file-on-another-server-possible/#findComment-561524 Share on other sites More sharing options...
ThunderAI Posted June 9, 2008 Author Share Posted June 9, 2008 <?php $file = "file.ext"; //the file name $remote_url = "http://example.com/"; //the server address (minus the file name) $local_dir = "c:/xampp/htdocs/your_folder"; //the directory you want the file saved to (absolute path) /* STOP EDIT */ $full_file = $local_dir.$file; $dl_file = file_get_contents($remote_url.$file); print $dl_file; $fh = fopen($full_file, "w+"); fwrite($fh, $dl_file); fclose($fh); ?> this should fix you up. That my friend is awesome. It works.. Now the question is, when i download a .rar file, when the download is over the screen in IE displays the contents of the file which is junk. Can I prevent that from happening so tat the script can continue on to do other stuff? Link to comment https://forums.phpfreaks.com/topic/109447-solved-force-download-of-a-remote-file-on-another-server-possible/#findComment-561545 Share on other sites More sharing options...
jonsjava Posted June 9, 2008 Share Posted June 9, 2008 remove print $dl_file; I had that in there for testing purposes. Link to comment https://forums.phpfreaks.com/topic/109447-solved-force-download-of-a-remote-file-on-another-server-possible/#findComment-561547 Share on other sites More sharing options...
ThunderAI Posted June 9, 2008 Author Share Posted June 9, 2008 Thanks so very much Link to comment https://forums.phpfreaks.com/topic/109447-solved-force-download-of-a-remote-file-on-another-server-possible/#findComment-561558 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.