Solved

Name of downloaded file

Posted on 2002-04-28
2
223 Views
Last Modified: 2006-11-17
Hi!

I have the following script on a site (dl.php):
$size = filesize("/home/b2048/dokument/" . $dok);
header("Content-Type: application/octet-stream");
header("Content-Length: $size");
header("Content-Disposition: inline; filename=$name");
header("Content-Transfer-Encoding: binary");
$fh = fopen("/home/b2048/dokument/" . $dok, "r");
fpassthru($fh);
exit;

It gets the specified file from a folder outside the www-root. When the Save as dialog box pop ups in IE it wants to save the document as dl.php. I want it to save it as the original filename (example: document.doc) without me editing it in the save as dialog. Is it possible to make PHP pass the filename in some way so it doesn't say dl.php?

Thanks!

/David
0
Comment
Question by:svanlund
2 Comments
 
LVL 7

Accepted Solution

by:
axis_img earned 100 total points
ID: 6975308
Hey David...

Do you see this line?

header("Content-Disposition: inline; filename=$name");

$name in that line is supposed to be the filename that you want it saved as. Try setting the $name variable to "document.doc" and see if that helps.

$name = "document.doc";
$size = filesize("/home/b2048/dokument/" . $dok);
header("Content-Type: application/octet-stream");
header("Content-Length: $size");
header("Content-Disposition: inline; filename=$name");
header("Content-Transfer-Encoding: binary");
$fh = fopen("/home/b2048/dokument/" . $dok, "r");
fpassthru($fh);
exit;


Let me know if that helps...
0
 

Author Comment

by:svanlund
ID: 6975410
It worked!
I changed the variable to $dok instead of $name.

The points are yours :-)

/david
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question