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="zi p";
$ct = "Content-type: application/octet-stream";
break;
case ($extlwr == ".mp3"):
$commonname="mp 3";
$ct = "Content-type: audio/mp3";
break;
case ($extlwr == ".pdf"):
$commonname="pd f";
$ct = "Content-type: application/pdf";
break;
case ($extlwr == ".doc"):
$commonname="do c";
$ct = "Content-type: application/ms-word";
break;
}
$size = strval(filesize ("$filepath$loc ation"));
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="'.$fi lename.'";');
header("Content-Transfer-Encoding: binary");
if($extlwr != ".pdf"){
header('Content-Length: '.$size);
}
readfile("$file path$location") ;
exit;
[/PHP]
any ideas?
thanks again
10 2855
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.
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
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?fi le=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 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?fi le=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?fi d=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
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.
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.mp 3
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?
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.mp 3
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.
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!
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?
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 women to got o hospital during the day, the day came and the women came asked for the key etc, I gave them this key but they had told me, they can't open door with that key, infact they had asked me to have unlawful relationship with them too.
So my...
|
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
"htttp://www.sound.com/files/bob.wav" to my own hard drive at
"c:\sound\bob.wav"?
I haven't found any good examples of such an operation in the
documentation at the Python website. Any suggestions are appreciated.
Thanks.
|
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
|
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 login, user is directed to a page called view.aspx which shows the
user the files in a directory and allows them to delete the files. This page
has a data grid having 4 columns - delete button, File Name, Last Write Time
and File Size. When a user...
|
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 for updating
these tables via an ftp site:
1) Post a .mdb file to our ftp web site that contains the updated tables. My
App code connects to the ftp site and gets the file name for any update files
on the site. I already have code to do this...
| |
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 browser to the script and
you're done.
But to me, the simplicity is a DISadvantage since I need to index
directories that are located down in the site hierarcy, and to which the
users won't have direct access.
|
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 solution to enable download resuming, but now, it remains
the splitting problem. Does anyone have any idea ?
|
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
|
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 on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script.
What You Need
Any recent...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |