I have a small problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
halimox
Forum Newbie
Posts: 1
Joined: Tue Apr 27, 2010 7:46 pm

I have a small problem

Post by halimox »

Hello,

I don't know where is the problem in this script :banghead:

1.html :

Code: Select all

<html><body>
<form method="post" action="download.php">
File name: <input type="text" name="FN" size="12"><br>
<input type="submit" value="OK">
</form></body></html>
download.php :

Code: Select all

<?php
$file = $FN;

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}
?>
test.html

Code: Select all

TEST
when I enter 'test.html' in the text field I can't download the file test.html' :(

thank you for your help.
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: I have a small problem

Post by yacahuma »

I always use the full system path when I download something not just the name.
Post Reply