473,394 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Download code

I have a set of jpg files on a page. I want to give the user the option to
downloadd all of them at once. What is the code to do that? It must exist
because many times users are presented with a download button and there must
be something behind it. Even if it is one file at a time, I can loop
through the list. As for a name, I can use the current name and if it is
one at a time, then the user can name each one.

Alternatively, I could zip it up into one file and then have the download.

So, I have two questions:

1 - What is the code to download a file to the user's computer?
2 - How do I zip up a set of jpg files on the server?

Shelly
Sep 8 '07 #1
7 1688
Sheldon Glickler wrote:
I have a set of jpg files on a page. I want to give the user the option to
downloadd all of them at once. What is the code to do that? It must exist
because many times users are presented with a download button and there must
be something behind it. Even if it is one file at a time, I can loop
through the list. As for a name, I can use the current name and if it is
one at a time, then the user can name each one.

Alternatively, I could zip it up into one file and then have the download.

So, I have two questions:

1 - What is the code to download a file to the user's computer?
This works for me. For a SINGLE file. In essence I call this from a URL
pointing to it with the file name as GET variable. This is via a
stament iek

<A HREF="filesend.php?filename="myfile.jpg">Myfile.jp g</a>

You will have to fudge your own ways to arrive at eh name, size and
filetype: the $content is the contents of the file: In my case from a
database. In yours you can just output the file:-
Filesend.php...fragment..
=========================
$name=$_GET['filename'];

// insert code to see if file exists, determine its size,

$mtype=get_mime($name); //get_mime() in my case parses /etc/mimetypes
and attempts a match from that to extension.

//spit out standard header stuff
header("Pragma: public");

header("Expires: 0");

header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

header("Cache-Control: public");

header("Content-Description: File Transfer");

header("Content-Type: ".$mtype);

header("Content-Disposition: attachment; filename=\"".$name."\"");

header("Content-Transfer-Encoding: binary");
print $content;
function get_mime($filename)
{
$default="application/force-download";
// first extract the extension
$array=explode(".",$filename); // split the name into the bits
separated by periods
$count=count($array);
if ($count<2) // if there IS NO extension..
return $default; // and let the user sort it out.
$ext=$array[$count-1]; // it will be the last element in the array..
$fp=fopen("/etc/mime.types", "r");
if(!$fp) return ($default); // no /etc/mime.types file
while (!feof($fp))
{
$buffer = fgets($fp, 128);
if (ctype_space($buffer{0}) || $buffer{0}=='#' || $buffer{0}=='\n')
continue; // skip empty lines. or lines starting with spaces
or hashes
sscanf($buffer, "%s %s %s %s %s %s \n",$mime_type,$extension,
$extension1, $extension2, $extension3, $extension4);
if ($ext==$extension || $ext==$extension1 || $ext==$extension2 ||
$ext==$extension3 || $ext==$extension4 )
{
fclose ($fp);
return($mime_type);
}
}
fclose($fp);
return $default;
}
2 - How do I zip up a set of jpg files on the server?
Oh..if you want to send a stream of all the checked fils in a ZIP?

I am sure there is a standard option in PHP for that.

>
Shelly

Sep 8 '07 #2

Sheldon Glickler wrote:
I have a set of jpg files on a page. I want to give the user the option to
downloadd all of them at once. What is the code to do that? It must exist
because many times users are presented with a download button and there must
be something behind it. Even if it is one file at a time, I can loop
through the list. As for a name, I can use the current name and if it is
one at a time, then the user can name each one.

Alternatively, I could zip it up into one file and then have the download.

So, I have two questions:

1 - What is the code to download a file to the user's computer?
2 - How do I zip up a set of jpg files on the server?

Shelly

as for zipping there is a decent class for that, easy to use, but
memory limits and so on might stop large jpegs being zipped, you can
also use 7zip command line version to reate an archive to disk which
you then serve as required. This is perhaps the best way depending on
whether you have shell access through php, as it can create many types
of archive, you then serve this file as normal

Sep 8 '07 #3
Sheldon Glickler wrote:
I have a set of jpg files on a page. I want to give the user the option to
downloadd all of them at once. What is the code to do that? It must exist
because many times users are presented with a download button and there must
be something behind it. Even if it is one file at a time, I can loop
through the list. As for a name, I can use the current name and if it is
one at a time, then the user can name each one.

Alternatively, I could zip it up into one file and then have the download.

So, I have two questions:

1 - What is the code to download a file to the user's computer?
2 - How do I zip up a set of jpg files on the server?

Shelly

Of course you do know they can always download an image by
right-clicking on the image and selecting "Save Image..." (or whatever
wording their browser uses) option. No PHP required.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 8 '07 #4

"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:W-******************************@comcast.com...
Sheldon Glickler wrote:
>I have a set of jpg files on a page. I want to give the user the option
to downloadd all of them at once. What is the code to do that? It must
exist because many times users are presented with a download button and
there must be something behind it. Even if it is one file at a time, I
can loop through the list. As for a name, I can use the current name and
if it is one at a time, then the user can name each one.

Alternatively, I could zip it up into one file and then have the
download.

So, I have two questions:

1 - What is the code to download a file to the user's computer?
2 - How do I zip up a set of jpg files on the server?

Shelly

Of course you do know they can always download an image by right-clicking
on the image and selecting "Save Image..." (or whatever wording their
browser uses) option. No PHP required.
Of course I know that! However, most users are not overly computer literate
and I would have to give them explicit instructions on what to do. A button
saying "Download" is much easier on the SU. (stupid user). Also, I would
like to have a button that says "Download All Pictures". For either of
these I need code behind the button submit.

Shelly
Sep 8 '07 #5
Shelly wrote:
"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:W-******************************@comcast.com...
>Sheldon Glickler wrote:
>>I have a set of jpg files on a page. I want to give the user the option
to downloadd all of them at once. What is the code to do that? It must
exist because many times users are presented with a download button and
there must be something behind it. Even if it is one file at a time, I
can loop through the list. As for a name, I can use the current name and
if it is one at a time, then the user can name each one.

Alternatively, I could zip it up into one file and then have the
download.

So, I have two questions:

1 - What is the code to download a file to the user's computer?
2 - How do I zip up a set of jpg files on the server?

Shelly
Of course you do know they can always download an image by right-clicking
on the image and selecting "Save Image..." (or whatever wording their
browser uses) option. No PHP required.

Of course I know that! However, most users are not overly computer literate
and I would have to give them explicit instructions on what to do. A button
saying "Download" is much easier on the SU. (stupid user). Also, I would
like to have a button that says "Download All Pictures". For either of
these I need code behind the button submit.

Shelly

I just put a note on the page as to what to do. Even the
least-knowledgeable users can figure that out.

But you'll have to zip the image(s) to ensure they are downloaded.
Otherwise the client browser may just display the image. You can't
control that from the server end.

For building zip files, you can start with:

http://www.php.net/manual/en/ref.zip.php
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 8 '07 #6
Of course you do know they can always download an image by
right-clicking on the image and selecting "Save Image..." (or whatever
wording their browser uses) option. No PHP required.
One issue here is that you might want to show a 'preview' image that's
small enough to load quickly and/or fit on the screen. But you want to
allow the visitor to download the full-resolution large image that is
not necessarily shown on the screen. So right-click would only work
for the browser-compatible images.

Sep 10 '07 #7
M. Katz wrote:
>Of course you do know they can always download an image by
right-clicking on the image and selecting "Save Image..." (or whatever
wording their browser uses) option. No PHP required.

One issue here is that you might want to show a 'preview' image that's
small enough to load quickly and/or fit on the screen. But you want to
allow the visitor to download the full-resolution large image that is
not necessarily shown on the screen. So right-click would only work
for the browser-compatible images.
That's possible, but that wasn't in the requirements the op posted.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 10 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sarah Akers | last post by:
GgF ----gL5cJ72EqiGIQ0SK65Rz Content-Type: text/html; Content-Transfer-Encoding: quoted-printable <html> <head> <style type=3D"text/css">.eyebrow { FONT-WEIGHT: bold; FONT-SIZE: 10px; TE=
0
by: jmd | last post by:
Hello. I want to write a C# program that does completely automatically what, until now, I do manually, witch is describe below : 1. I launch IE (6) 2. I browse to my desired download page, say...
0
by: Buddy Ackerman | last post by:
I am trying to implment a file download via a link such that when clicked, instead of starting the default application for that type of file the user will be presented with a download dialog...
0
by: Rhys666 | last post by:
Basically I have a link that opens my download page and the querystring identifies the type of 'template' Excel spreadsheet has asked to download. The download page reads the querystring,...
4
by: Nathan Sokalski | last post by:
I want to give visitors to my site the option of downloading a generated ..txt file by clicking a button. I know how to generate text files, but how do I cause the browser to pop up one of those...
18
by: jmd | last post by:
Hello, I posted the following in the C# forum but without one answer. But perhaps now in vb.net someone has some guidelines ! This is my question : I want to write a vb.net program that does...
2
by: Jan Paul van de Berg | last post by:
I have a piece of software that people can download and a third party promoting that software. In order for them to be able to count the number of downloads, I have to put a tracking code on my...
1
by: a.r.austin | last post by:
Hello, I am trying to download a few files one after another from a remote server. Problem is that I don't know how to, or if I am able at all, set a time out for download. I don't want to time...
16
by: matt | last post by:
I have used some free code for listing files for download, but I want to send an email to the administrator when the file has been downloaded. I have got some code in here that does it, but it will...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.