downloading txt file
Moderator: General Moderators
- itsmani1
- Forum Regular
- Posts: 791
- Joined: Mon Sep 29, 2003 2:26 am
- Location: Islamabad Pakistan
- Contact:
downloading txt file
I created a file on server now i want to download that file, how can i do so? i don't want to open that file in my web page i want to download this file
Please help
thanks
Please help
thanks
you need to use the header() function
There should be some useful functions on the user-contributed notes on this page:
There should be some useful functions on the user-contributed notes on this page:
Code: Select all
header()- itsmani1
- Forum Regular
- Posts: 791
- Joined: Mon Sep 29, 2003 2:26 am
- Location: Islamabad Pakistan
- Contact:
I tried this code but result is not what is required.
when i click on asdf it opens the file instead of downloading it.
when i click on asdf it opens the file instead of downloading it.
Code: Select all
header('Content-Type: application/txt');
header('Content-Disposition: attachment; filename=testFile.txt');
echo "<a href=\"testFile.txt\">asdf</a>";here is a sample header
Code: Select all
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: application/text");
header("Content-Disposition: attachement; filename=testfile.txt");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize('testfile.txt'));
echo readfile('testfile.txt');
exit;- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
psst, we don't echo readfile() 
- itsmani1
- Forum Regular
- Posts: 791
- Joined: Mon Sep 29, 2003 2:26 am
- Location: Islamabad Pakistan
- Contact:
i tried it at :
http://www.dizyn.com/bindex.php
and it showed me the text file contents. I want this to give me an option for saving file on my local disc.
Please help me i don't know what's the problem.
I tried by removing echo readfile('testfile.txt'); but it did not worked. I wanted to save file on my on PC not on server.
thanks for your help.
please help me thanks
http://www.dizyn.com/bindex.php
and it showed me the text file contents. I want this to give me an option for saving file on my local disc.
Please help me i don't know what's the problem.
I tried by removing echo readfile('testfile.txt'); but it did not worked. I wanted to save file on my on PC not on server.
thanks for your help.
please help me thanks
the only other thing I can think of then would be to change the content-type.
there are several mime types for text files.
here's a list:
http://filext.com/detaillist.php?extdet ... rch=Search
there are several mime types for text files.
here's a list:
http://filext.com/detaillist.php?extdet ... rch=Search
- itsmani1
- Forum Regular
- Posts: 791
- Joined: Mon Sep 29, 2003 2:26 am
- Location: Islamabad Pakistan
- Contact:
I solved it this way:
and now its working fine @ http://www.dizyn.com/bbindex.php
Code: Select all
<?
$myFile = "testFile.txt";
$fh = fopen($myFile, 'w+') or die("can't open file");
$stringData = "Hellozzz";
fwrite($fh, $stringData);
$fname = "testFile.txt";
header("HTTP/1.1 200 OK");
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=$fname");
header("Content-Transfer-Encoding: binary");
echo readfile('testFile.txt');
?>