...

View Full Version : File Download Problem



PutterPlace
04-02-2007, 12:30 AM
I recently created a script that creates a txt file in a randomly named folder within a specified folder. I would like to know how I can make this txt file automatically download...?

I have heard of placing the URL within an iframe or even using a meta refresh tag to download it, but since I'm working with a .txt file, by default it would load the file within the browser instead of present the user with a downloadable file. This is an inconvenience to a lot of people because then they have to manually save the file (I wouldn't mind, but a lot of other people would). By the way, the download link is parsed with PHP. ;) Not sure if that matters.

Is there something I can do with .htaccess to force the file to be downloaded?

Thanks in advance.

iLLin
04-02-2007, 12:42 AM
I believe its how you setup your headers?

header('Content-Disposition: attachment; filename="downloaded.pdf"');

Not sure but I 'think' thats how you force a download when a link is clicked.

PutterPlace
04-02-2007, 12:45 AM
I would I go about implementing that with my links?

iLLin
04-02-2007, 12:47 AM
Throw up some code.

PutterPlace
04-02-2007, 12:57 AM
:P Nevermind. I figured out that I could implement that information into my .HTACCESS file:

<Files *.txt>
ForceType application/octet-stream
Header set Content-Disposition attachment
</Files>


Thanks for your help.

iLLin
04-02-2007, 01:00 AM
LoL the php version is almost the same



<?php

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

readfile("filename.suffix");

?>


Set that up as a php page and use it for all your txt files dynamically, OR w/e else you want to download.

PutterPlace
04-02-2007, 02:44 AM
I just figured I would use the .htaccess and have the script copy the .htaccess to the random directory that is created upon the script's execution. :)

It seems to do just fine. Thanks again.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum