You are here: text file download on .php page « PHP Programming Language « IT news, forums, messages
text file download on .php page

Posted by R.A.M. on 01/01/08 13:07

Hello,
I am learning PHP5. I have little experience.
I have created a website in which I want to put a link to download a text
file. When I used simple
<a href="Dir/File.txt">Download file</a>
I had such problem that instead of dowloading the file contents was
displayed in browser. In some book on PHP5 I found a "solution": create a
link
<a href="Download.php?dir=Dir&file=File.txt">Download file</a>
and prepare Download.php file:

<?php
if (isset($_GET['dir']) && isset($_GET['file']))
{
$file = $_GET['dir'] . '/' . $_GET['file'];
$fd = fopen($file, 'r');
$size = filesize($file);
$contents = fread($fd, $size);
fclose($fd);
header("Content-Type: application/octet-stream");
header("Content-Length: $size;");
header("Content-Disposition: attachement; filename=$file");
echo $contents;
}
?>

But... again the file contents is displayed instead of downloading.
Could you help me please to write it correctly?
Thank you!
/RAM/

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация