Hello guyz,
I have this code bellow which is to download stored files on directory. I was using $reload=$_SERVER; for page reload and I was curious if would it be possible to use $_SERVER and reload php page two or more times?.. cause when I clicked on a link 'song title' I made, it does not download it.. I think my code for downloading the file is correct cuz i've tried it on the other page. any ideas please?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<meta charset="utf-8">
<title></title>
<head>
<?php
$reload=$_SERVER['PHP_SELF'];
?>
</head>
<body>
<form method='post' action="<?php echo $reload;?>">//first reload
<p>Search:<input type='text' name='search'/>
<input type='submit' name='submit' value='search'/></p>
</form>
<?php
if(isset($_POST['submit']))
{
include 'dbconnect.php';
$query="SELECT userfiles FROM userprofile";
$result=mysql_query($query);
$numrows=mysql_num_rows($result);
$search=$_POST['search'];
if($numrows>0)
while($path=mysql_fetch_assoc($result))
{
$path=$path['userfiles'];
if($dir=opendir($path))
{
while(($file=readdir($dir))!==false)
{
if((filetype($path."/".$file))!="dir")
{
$found=stripos($file, $search);
if($found!==false)
{
$reload=$_SERVER['PHP_SELF']."?file=$file&path=$path";
echo "<br/><a href='$reload'>$file</a>";//second reload
}
}
}
}
}
//I think the problem starts here. It didn't even get into the statement IF even though I have successfully set the file variable.
if(isset($_GET['file']))
{
echo 'set';
$file=$_GET['file'];
$path=$_GET['path'];
$path=$path."/".$file;
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($path));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($path));
ob_clean();
flush();
readfile("$path");
}
}
?>
</body>
</html>
Thanks in advance...