rlelek Posted July 5, 2008 Share Posted July 5, 2008 Hey Everyone! I just had a question on how to go about downloading batch files... For Example, I would first create an array of numbers, say 1-1000, and then like for php to download files to a set directory while replacing parts of the following URL with values from the array in a "foreach" loop. $url = "http://www.example.com/*arrayvalue*.*fileextention*" The array could also be words or a combination of words and numbers, but the main thing is... how do I get PHP to download the file from the generated url? Can that even be done? Thank you! Link to comment https://forums.phpfreaks.com/topic/113289-how-to-download-files/ Share on other sites More sharing options...
DarkerAngel Posted July 5, 2008 Share Posted July 5, 2008 cURL fopen file_get_contents all are methods but also with some methods your server must be configured for 'URL fopen' with cURL I do not believe you need to have URL fopen on. Link to comment https://forums.phpfreaks.com/topic/113289-how-to-download-files/#findComment-582055 Share on other sites More sharing options...
rlelek Posted July 5, 2008 Author Share Posted July 5, 2008 Thanks for the quick reply I was looking at wget and cURL, but could not figure out how to make it into a script? Can you please lead me in the right direction/help me write it? Link to comment https://forums.phpfreaks.com/topic/113289-how-to-download-files/#findComment-582056 Share on other sites More sharing options...
rlelek Posted July 5, 2008 Author Share Posted July 5, 2008 Okay, How Would this work? *It's pretty much all from php.net, so it is not my own.. <?php /* This is the start of the foreach loop*/ // create a new cURL resource $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, "http://www.example.com/*filename*.*extention*"); curl_setopt($ch, CURLOPT_HEADER, 0); // grab URL and pass it to the browser curl_exec($ch); // close cURL resource, and free up system resources curl_close($ch); /* End of Foreach */ ?> But how would i bypass the browser opening and just download the file... Or.... how could i automatically close the browser after download? Link to comment https://forums.phpfreaks.com/topic/113289-how-to-download-files/#findComment-582060 Share on other sites More sharing options...
PC Nerd Posted July 5, 2008 Share Posted July 5, 2008 well if you are running this like nightly or weekely etc - set the script up as a cron. If its a download page where you download the file, and then the client downloads from you... hten just do the header() to force the download dialog - and then display a page, even with simple content like: "Your douwnload should start in 30 seconds... etc etc ".... gdlk Link to comment https://forums.phpfreaks.com/topic/113289-how-to-download-files/#findComment-582062 Share on other sites More sharing options...
DarkerAngel Posted July 5, 2008 Share Posted July 5, 2008 Also it will not actually "Open a browser" window per-se, it's all done beind the script and that script isn't vary well written and does not pass the results of the query. Link to comment https://forums.phpfreaks.com/topic/113289-how-to-download-files/#findComment-582068 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.