Jump to content

Problems with reading file


Semas

Recommended Posts

Hello everyone, i have some problems using readfile(); it worked before i reinstalled windows and now... it doesn't.

 

Here is the code:

<?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");
    }
}
?>

 

P.S. When i open files directly trough browser i can see them, but when using files.php and this code it does not work

P.SS. If I'm doing something wrong, tell me.

 

examples:

http://78.63.197.71/?page=Files&type=Image&file=525bceda113719785656d3b3b238336b

http://78.63.197.71/images/funny-hellos-172.jpg

Link to comment
Share on other sites

Are the paths correct?

Have you echoed out the filepath to check?

readfile("$dir/{$result['file_name_full']}");

Have the files got read permissions?

What is the error you are receiving?

Filepaths are ok.

But im not sure about the permisions... And there is no errors.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.