Problems with "readfile();"
Posted: Thu Dec 18, 2008 2:45 am
Hello everyone, i have some problems with readfile(); it worked before i reinstalled windows and now... it dosent.
Here's the code:
P.S. When i open files direcly trouth browser i can see them, but when using files.php and this code it does not work
examples:
http://78.63.197.71/?page=Files&type=Im ... b3b238336b
http://78.63.197.71/images/funny-hellos-172.jpg
Here's the code:
Code: Select all
<?php
include("config.php"); //there is connection to mysql server and so on...
$query = mysql_query("SELECT * FROM files WHERE file_code=\"{$_GET['file']}\""); //selects a file from mysql server with hash that is in url
$result = mysql_fetch_array($query); //puts everything in array
/* im not sure but i think there is one more problem with headers */
if($result['file_type'] == "Image"){
$header = "Content-type: image/jpg";
$dir = "images";
$dl_header = "Content-Disposition: attachment; filename=\"$site_linkimages/{$result['file_name_full']}\"";
}else if($result['file_type'] == "Flash"){
$header = "Content-type: application/x-shockwave-flash";
$dir = "flash";
$dl_header = "Content-Disposition: attachment; filename=\"$site_linkflash/{$result['file_name_full']}\"";
}else if($result['file_type'] == "Games"){
$header = "Content-type: application/x-shockwave-flash";
$dir = "games";
$dl_header = "Content-Disposition: attachment; filename=\"$site_linkgames/{$result['file_name_full']}\"";
}else if($result['file_type'] == "Music"){
$header = "Content-type: audio/mpeg";
$dir = "music";
$dl_header = "Content-Disposition: attachment; filename=\"$site_linkmusic/{$result['file_name_full']}\"";
}
if($_GET['type'] == "download"){
if(mysql_num_rows($query) > 0){
/* i can download the file */
header($header);
header($dl_header);
header("Content-Type: application/download");
header("Content-Length: ".filesize("$dir/{$result['file_name_full']}"));
readfile("$dir/{$result['file_name_full']}");
}
}else if($_GET['type'] == ""){
if(mysql_num_rows($query) > 0){
/* download works but readinng and displayng in site dosent work, i have no idea why. */
header($header);
readfile("$dir/{$result['file_name_full']}");
}else {
header("Location: $site_link");
}
}
?>examples:
http://78.63.197.71/?page=Files&type=Im ... b3b238336b
http://78.63.197.71/images/funny-hellos-172.jpg