CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Download multiple graphic files

Print topic Send  topic

Author Message
saseow

Posts: 744
Posted: 07/01/2012, 1:00 AM

I have a request from a client who wants to download about 500 graphic files that have been uploaded to the server. I can get the file names from the DB table but then if I use the Header stuff all the warnings appear about "Headers have already been sent" appear.
I am sure there must be a way of doing this. Any ideas?

$dir ="./pics/";
$id = CCGetParam("s_ID");
$db = new clsDBjob_manage();
$sql= "Select pic from photos where project_id = ".$id;
$db->query($sql);
while($db->next_record())
{
$file_name= $db->f("pic");
$file = ($dir.$file_name);
$original_filename = preg_replace("/^\d+\./", "", $file_name);
header("Content-Length: " . filesize($file));
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$original_filename\"");
header("Content-Transfer-Encoding: binary");
readfile($file);
}
$db->close();
View profile  Send private message
MichaelMcDonald

Posts: 640
Posted: 07/01/2012, 3:29 AM

If this is outputting straight to file, then you have to remove all formatting.
_________________
Central Coast, NSW, Australia.

View profile  Send private message
saseow

Posts: 744
Posted: 07/01/2012, 4:37 AM

Not sure what you mean. The files are graphic files: jpg,png etc.etc.
$dir is where the files are uploaded to. i.e. hard coded.
View profile  Send private message
DataDoIT
Posted: 07/01/2012, 6:35 AM

What do you mean by "download"? Are you grabbing the file and spitting
it to the user's browser? or are you grabbing the file and putting it
somewhere else on disk?
saseow

Posts: 744
Posted: 07/01/2012, 7:11 AM

I want to grab the file and put it on the users disk, most probably the default download folder for his browser will be fine.

I have had a look at zipping the files on the server and then downloading the single zip file but there are several problems with this as the zipped file may well be too large and I do not know what version of PHP they are running.
View profile  Send private message
DataDoIT
Posted: 07/01/2012, 10:18 AM

You're only going to be able to spit the file out to the user's browser
one at a time. So you'll need to manage how you're doing that with your
do-while loop, such as writing a trigger back to the database that the
file was downloaded for the particular user session.

The other option is to build a zip/compressed file and present that back
to the user's browser. Either way, you need to 'exit' after presenting
custom headers. Put an exit command after your readfile() function call.

Have a look at how Google does it with their Drive or Docs feature.
Single files are downloaded in their native formats. Multiple files get
compressed into a zip file.
saseow

Posts: 744
Posted: 07/01/2012, 6:33 PM

Thanks DataDoIT. I was afraid that this would be the case.

A single zip file is not an option because of the size and also, I am not sure of the PHP zip functions being there.

Anyway, I will have a look at the trigger idea or perhaps zipping the files in batches.

Another tedious option is to add all the data into the FileZilla sqlite DB and let it do the download. I am just not too sure at this stage how to proceed.

Thanks again for the reply!!
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.