Solved

Name of downloaded file

Posted on 2002-04-28
2
198 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

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now