Forum Moderators: coopster

Message Too Old, No Replies

Making download script

         

wavesurf

12:05 pm on Nov 26, 2003 (gmt 0)

10+ Year Member



Does anyone know how to send a file to the client browser for download, instead of actually opening the file in a client browser?

I don't seem to figure out how to do this, and I just can't understand how to do this.

Thanks for any help.

henry0

12:35 pm on Nov 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I might be off topic but you may use a Zip file

wavesurf

12:48 pm on Nov 26, 2003 (gmt 0)

10+ Year Member



Yeah, I do know that, but it is a part of a file management system and I was kind of hoping to implement a script that makes the user able to download any file.

henry0

2:53 pm on Nov 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if you can allow your user to D-load files
and modify my script to your needs
I have a script that query a DB
and allow a D-load as a cvs format then in XL
you can modify it and select only to output files you agreed on

that thing is 300+ lines so if you are interested I will mail it to you

Henry

NickCoons

3:49 pm on Nov 26, 2003 (gmt 0)

10+ Year Member



wavesurf,

You need to send the correct header information to the browser when trying to download a file instead of having it opened.

header("Content-type: [content-type]");
header("Content-Disposition: attachment; filename=[filename]");
readfile("[file-on-server]");

You can replace [content-type] with the actual content-type of the file, this way the browser can handle it however it chooses. If you want to always force a download, then you can change this to a stream of some sort, like application/octet-stream.

Replace [filename] with the name you want their browser to save the file as by default (this can be different than the actual filename, but you should have it there otherwise it will try to save the file as the name of your PHP script that prompted the download), and replace [file-on-server] with the path and name of the file as it is on your server.