Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Name of downloaded file

Posted on 2002-04-28
2
Medium Priority
?
247 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 400 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

916 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