473,386 Members | 1,842 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,386 software developers and data experts.

Script to download files only allows 1 download at a time?

5
Hi,
I have a script which based on an id passed to the page is retrieving a filename and path from the database of a file and then outputting the file for download. I specifically did it this way (see the code below) so user would have a choice of "Saving" or "Running" the file.
The problem is that with this method when a file is clicked for download the user cant then select another file to download. It seems like this script prevents the server from allowing more than one download at a time. I dont know much about this, so any help would be really appreciated!!!
Thanks,
here is the code which prompts the download
[PHP]
switch($extlwr) {
case ($extlwr == ".zip"):
$commonname="zip";
$ct = "Content-type: application/octet-stream";
break;
case ($extlwr == ".mp3"):
$commonname="mp3";
$ct = "Content-type: audio/mp3";
break;
case ($extlwr == ".pdf"):
$commonname="pdf";
$ct = "Content-type: application/pdf";
break;
case ($extlwr == ".doc"):
$commonname="doc";
$ct = "Content-type: application/ms-word";
break;

}
$size = strval(filesize("$filepath$location"));

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("$ct");
header('Content-Disposition: attachment; filename="'.$filename.'";');
header("Content-Transfer-Encoding: binary");
if($extlwr != ".pdf"){
header('Content-Length: '.$size);
}
readfile("$filepath$location");
exit;
[/PHP]

any ideas?
thanks again
Feb 22 '07 #1
10 2804
xwero
99
if you output the file to the browser the file is generated so there is nothing else to do but wait until the file is fully generated.

You could save the files somewhere in a cache directory and display obfuscated for the download.

you could also add

[PHP]header("Content-Type: application/octet-stream");[/PHP]

to the header to force the file to be downloaded.
Feb 22 '07 #2
Gotts
5
Thanks for your help
Even though I am outputting it to the browser, I am doing this in a new window. Why shoudl this stop the user from being able to click on another link in the original window to initiate a new download?

What does this mean?
"display obfuscated for the download."

Thanks again
Feb 22 '07 #3
xwero
99
Thanks for your help
Even though I am outputting it to the browser, I am doing this in a new window. Why shoudl this stop the user from being able to click on another link in the original window to initiate a new download?

What does this mean?
"display obfuscated for the download."

Thanks again
I have no experience with it myself but have you tried a checkboxlist so that the user can choose which files he wants to download and then output the different files in new windows?


Sorry it had to be display an obfuscated link for the download. Lets say a file is in the directory /upload/nice.jpg. You put in the download link something like download.php?file=fe4564ds4. the file parameter can be created from the session id and the directory of filename mixed in it in a pattern you know how to get it out again. This way you don't have to generate the files everytime someone wants to download them and you are protected from hot linking.
Feb 22 '07 #4
Gotts
5
I have no experience with it myself but have you tried a checkboxlist so that the user can choose which files he wants to download and then output the different files in new windows?


Sorry it had to be display an obfuscated link for the download. Lets say a file is in the directory /upload/nice.jpg. You put in the download link something like download.php?file=fe4564ds4. the file parameter can be created from the session id and the directory of filename mixed in it in a pattern you know how to get it out again. This way you don't have to generate the files everytime someone wants to download them and you are protected from hot linking.
I am sorry, I am still not clear. Why do I need to be generating files at all? in fact what does it mean to be generating files?
I am using a download.php?fid=24 where the fid is the fileid in the database so it knows which file to pull. I just dont know why when I output the file to browser it wont allow the user to download a different file. If the user clicks a different file then only once the first download completes does the second window popup asking the user where to save the file? In fact more than that - the whole website slows down for the user and they cant even browse to other pages on the site while a file is being downloaded?? There is obviously something i am doing very wrong here?
thanks for your patience and help
Feb 22 '07 #5
xwero
99
If you output the field content of the database it is one long string. To make it readable for humans the string is preceded by a header. this header tells the browser the file needs to be generated in that format. Then you add the content. So the file gets build from that string. Once it's finnished you see the image, can listen to the song, ...

it's like a string you manipulate with string functions. but now php does the hard work for you.

It is better to store the files in directories. This way no database connection is needed and the file already is in the human readable format.

Because it's such a long string if the file is large it takes up all the server memory and you can't do anything else until the string is read out.
Feb 22 '07 #6
Gotts
5
If you output the field content of the database it is one long string. To make it readable for humans the string is preceded by a header. this header tells the browser the file needs to be generated in that format. Then you add the content. So the file gets build from that string. Once it's finnished you see the image, can listen to the song, ...

it's like a string you manipulate with string functions. but now php does the hard work for you.

It is better to store the files in directories. This way no database connection is needed and the file already is in the human readable format.

Because it's such a long string if the file is large it takes up all the server memory and you can't do anything else until the string is read out.
So would the following work, I think its similar to what you were explaining before,
if someone clicks on a link a download script will copy the file from its source directory into a temporary directory with some temp filename and then serve that file to the user, not in the way I am serving it now with the headers and content but just by redirecting them to that file eg http://www.url.com/tempdir/tempfilename.mp3
Would that work? or do you have a better suggestion

my only issue is that I would need to delete these temp files and when would I know to delete them?
Feb 22 '07 #7
xwero
99
So would the following work, I think its similar to what you were explaining before,
if someone clicks on a link a download script will copy the file from its source directory into a temporary directory with some temp filename and then serve that file to the user, not in the way I am serving it now with the headers and content but just by redirecting them to that file eg http://www.url.com/tempdir/tempfilename.mp3
Would that work? or do you have a better suggestion

my only issue is that I would need to delete these temp files and when would I know to delete them?
It's a way to go. To know how when to delete the picture you could put the date the file is clicked into a database table and temp file that are older then 30 minutes will be deleted.
Feb 22 '07 #8
Gotts
5
It's a way to go. To know how when to delete the picture you could put the date the file is clicked into a database table and temp file that are older then 30 minutes will be deleted.
actually I can just compare it to the time now, and more than 30 minutes delete it!
sounds good, thanks so much for your help!
Feb 22 '07 #9
hey there!

I'm having the same problem. I'm using 2 servers though. One on which i have my php pages & one on which i put my mutlimedia...

I got the script to work, however, the site gets "stuck", until the download is complete...

Is there any way I could solve this problem please?
Sep 3 '07 #10
hey there!

I'm having the same problem. I'm using 2 servers though. One on which i have my php pages & one on which i put my mutlimedia...

I got the script to work, however, the site gets "stuck", until the download is complete...

Is there any way I could solve this problem please?
I had this problem and it was a session header problem.
If you have "session_start();" at the top of the page where you're initiating the download, it keeps the session header in use thus not allowing any other header information to be sent/received from that session.

If you remove session_start(); from the top of the page, this should no longer be a problem.
Oct 14 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: PeopleIhavefeeling | last post by:
Real conspiracy theory's script: leaving the key Assalam u'Alekum :), The second night , before the two women came in, Mahmud Kurchu left a key with me, he told me I have to give this key to the...
8
by: Radioactive Man | last post by:
I am fairly new to the latest verion of Python and using it on windows 95, 2000, and/or XP. What libraries, modules, functions, etc. would I need to set up a Python script to download a file, say...
11
by: Wentink | last post by:
Does anybody have a simple script that let's me popup a picture from a thumbnail? The ones i found are all very very complicated and messy in the source... Thanks, Tintin
3
by: Joe | last post by:
Hi, I have written a webpage that allows a user to delete files in asp.net with I am having a small problem. To access this page a user has to login via login.aspx page. After successful...
1
by: rdemyan via AccessMonster.com | last post by:
My App has 10 or so tables that we provide that contains proprietary data. This data will need to be updated once or twice a year. I would like some comments, suggestions on my proposed strategy...
2
by: Danny Boy | last post by:
Hi, "Snif" is an excellent little script to index files and directories. It's just one single file, and the advantage is that you merely drop it into the directory you want to index, point a...
3
by: Bouffa | last post by:
Hello everyone, I suppose you all know force-download scripts. The problem is that these scripts don't allow files to be splitted when downloading them via a download manager. I've found a...
3
by: aRTx | last post by:
I have try a couple of time but does not work for me My files everytime are sortet by NAME. I want to Sort my files by Date-desc. Can anyone help me to do it? The Script <? /* ORIGJINALI
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.