Solved

Name of downloaded file

Posted on 2002-04-28
2
234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

617 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