Hi
can any body help me and find out the problem. I dont have problem in uploading and in database(my files in the folder and their paths in mysql) but when i download files. instead of text, there is different kind of data appears. pdf file says "file is corrupted,can not open". I am using WAMPserver 2.0b. please help!
php file to show links
<?php
require ('dbcon.php');
$query = "SELECT id, name,type FROM upload2";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
echo "Database is empty <br>";
}
else
{
while(list($id, $name,$type) = mysql_fetch_array($result))
{
//echo $id;
echo "<h3><a href=mydownload2.php?id=". $id .">" . $type ."</a></h3>";
}
php file to download
<?php
if(isset($GET['id']))
{
$id = $GET['id'];
require ('dbcon.php');
$query = "SELECT name, type, size, path FROM upload2 WHERE id =".$id .";";
$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $filePath) = mysql_fetch_array($result);
$file_extension = $type;
switch ($file_extension)
{
case "html": $ctype="text/html"; break;
case "pdf": $ctype="application/pdf"; break;
case "doc": $ctype="application/msword"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpg": $ctype="image/jpeg"; break;
case "mp3": $ctype="audio/mpeg"; break;
case "wav": $ctype="audio/x-wav"; break;
case "mpe": $ctype="video/mpeg"; break;
case "mov": $ctype="video/quicktime"; break;
case "avi": $ctype="video/x-msvideo"; break;
default: $ctype="application/force-download";
}
header("Content-Disposition: attachment; filename= $name");
header("Content-length:$size");
header("Content-type:$file_extension");
readfile($filePath);
exit;
}
else{echo "file cannot be downloaded";}
?>