PHP download file script

Dear All,

I am not a PHP programmer, I am UI developer, I am making a site, there is a form mentioning some links:
I want to do if user click on that link the save window should come up on screen and user should save that file into their place.
for that I want a PHP script, if any 1 have that script plz. plz. help me out in this…

Warm Regards

Hello shahzadsiddiqui8 ,

Which file u wnat user to download…

u dont need to write code to download zip,pdf,docx,xls,… files.
u only need to write file path in href of anchor tag.
e.g. <a href=‘’>Download file</a>
if user click on the above link the save window will come up.

I am using pdf and word files in my links…

One option would be to have a link to a php script that then causes the download. Something someone once gave me is:

$filename = "something.doc";

header("Content-Length: " . filesize($filename));
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=something.doc');


With this, you would need to name the script something.php and when you click on the something.php link, you would then download the something.doc.

You may be able to figure a way to rewrite this to automate the task, but when I first was given this, I manually created the short php file for every file I had ready to be downloaded.

Download an attachment in PHP is pretty simple. Just use the following lines of code in a separate PHP file, say download.php.

/*Actual filename = '' (Unknown to the viewers).
When downloaded to be saved as ''.
@header("Content-type: application/zip");
@header("Content-Disposition: attachment; filename=$filename");
echo file_get_contents('');

Now whenever you open this file on your browser window a download dialog box will appear asking whether you want to save the file ‘’.