Log in

View Full Version : Download zip file from site itself



rsmaha
02-08-2010, 06:19 AM
Hi All,


Is this possible to keep downloading in the site itself ?
ie) Instead of download popup ask save?open?cancel? then proceed downloading , i have to keep downloading in site itself like buffering?

djr33
02-08-2010, 07:15 AM
No. Unless the file can be opened as a "web page", like images and some media (quicktime movies, for example), then a file must be downloaded. The browser determines this behavior.

It is *theoretically* possible to design a way to download a file with a progress bar, but that would mean creating an applet based on a browser plugin to do that. I do not believe it would be very easy (maybe not possible) with flash, and I think this means you would have to use a Java applet. The only other option would be using ActiveX which only works in internet explorer. This would be a bad idea, though.

rsmaha
02-09-2010, 07:35 AM
thanks for reply.

rsmaha
02-09-2010, 07:40 AM
Now im look into another methed.
Im having following code



//function to zip and force download the files using PHP
function zipFilesAndDownload($file_names,$archive_file_name,$file_path)
{
//create the object
$zip = new ZipArchive();
//create the file and throw the error if unsuccessful
if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE )!==TRUE) {
exit("cannot open <$archive_file_name>\n");
}

//add each files of $file_name array to archive
foreach($file_names as $files)
{
$zip->addFile($file_path.$files,$files);
}
$zip->close();

//then send the headers to foce download the zip file
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=$archive_file_name");
header("Pragma: no-cache");
header("Expires: 0");
readfile("$archive_file_name");
exit;
}


$file_names=array('test.php','test1.txt');
$archive_file_name='zipped.zip';
$file_path=dirname(__FILE__).'/';
zipFilesAndDownload($file_names,$archive_file_name,$file_path);


Here i have to rectify 2 problems
1.Download code should ask save location
2.One more copy is created in source location.If i upload this code into server, My server will be overloaded.

How to resolve this? Plz help

djr33
02-09-2010, 04:41 PM
I don't understand. This is the opposite of what you want. This creates a zip file that will do the DEFAULT behavior: it will popup and ask where you want to save it or if you want to open it, like any normal zip file: this is just converting OTHER files to zip files. According to your first post, this is not what you want.

1. The browser will determine where it saves. Many will let the user choose (either for each download individually or create a general setting for where to save).
2. I don't understand. If your server will be overloaded, then don't use this code or get a better server. If you decide you want to store the file on the server, then just use fopen() fwrite() fclose() etc-- look at php.net for info on those. There are examples.