Jump to content

How To Download Files?


rlelek

Recommended Posts

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

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?

 

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.