A G E N T
2007-09-02 00:41:24
Hi there, this was originally in "other programming languages", until I realized that there was a perfectly good web languages forum. Anyway, here is the post:
Basically I was trying to make a download script where you put in the name of the file you wanted into a box, it looks for that file in one directory (always the same one, called /downloads/). I can't seem to get it to work though, it never finds the file properly. If anyone knows what they're doing, can they please help me? Thanks :)
[PHP]<html>
<div align='center'><font size=20>DOWNLOADS</font></div>
<br>
Files available for download:<br>
<ul>
<li>testfile.txt
</ul>
<?php
echo "<form method='post' action='download.php'>
<input name='file' type='text'>
<input type='submit'>
</form>";
$file=$_REQUEST['file'];
if (!isset($file)) {die("Please specify file name for download.");}
function find_file($fname)
{
if (is_file('/downloads/'.$fname))
{
$file_path = '/downloads/'.$fname ;
return($file_path);
}
}
$fsize = filesize($file_path);
if (find_file($file))
{
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-Disposition: attachment; filename=\"$file_path");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$fsize);
}else{
echo "That file does not exist. Please double-check your spelling.";
}
?>
</html>[/PHP]
Anyone who can help me get this to work would be greatly appreciated. Also, if anyone knows how to work mySQL, please PM me. It would be appreciated too… but more so the PHP ;)
Basically I was trying to make a download script where you put in the name of the file you wanted into a box, it looks for that file in one directory (always the same one, called /downloads/). I can't seem to get it to work though, it never finds the file properly. If anyone knows what they're doing, can they please help me? Thanks :)
[PHP]<html>
<div align='center'><font size=20>DOWNLOADS</font></div>
<br>
Files available for download:<br>
<ul>
<li>testfile.txt
</ul>
<?php
echo "<form method='post' action='download.php'>
<input name='file' type='text'>
<input type='submit'>
</form>";
$file=$_REQUEST['file'];
if (!isset($file)) {die("Please specify file name for download.");}
function find_file($fname)
{
if (is_file('/downloads/'.$fname))
{
$file_path = '/downloads/'.$fname ;
return($file_path);
}
}
$fsize = filesize($file_path);
if (find_file($file))
{
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-Disposition: attachment; filename=\"$file_path");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$fsize);
}else{
echo "That file does not exist. Please double-check your spelling.";
}
?>
</html>[/PHP]
Anyone who can help me get this to work would be greatly appreciated. Also, if anyone knows how to work mySQL, please PM me. It would be appreciated too… but more so the PHP ;)