0

I have a file in which a user can view its stored files. I want that only the logged in user and it can only be viewed by that member who has stored that file. It works fine when I view other files like .html, .txt etc. But when I view any image, it doesn't work.

This is my script :

require ('config.php');
$id = intval($_GET['id']);

$dn2 = mysql_query('select authorid from files where uploadid="'.$id.'"');

while($dnn2 = mysql_fetch_array($dn2))
{
if(isset($_SESSION['username']) and ($_SESSION['userid']==$dnn2['authorid'] or $_SESSION['username']==$admin)){ 

 $query = "SELECT data, filetype FROM files where uploadid=$id"; //Find the file, pull the filecontents and the filetype
    $result = MYSQL_QUERY($query);    // run the query

    if($row=mysql_fetch_row($result)) // pull the first row of the result into an array(there will only be one)
    {
        $data = $row[0];    // First bit is the data
        $type = $row[1];    // second is the filename

        Header( "Content-type: $type"); // Send the header of the approptiate file type, if it's' a image you want it to show as one :)
        print $data; // Send the data.
    }
    else // the id was invalid
    {
        echo "invalid id";
    }
}
}

How can I view the image?

Tunaki
  • 132,869
  • 46
  • 340
  • 423
shivkhaira
  • 56
  • 1
  • 8

0 Answers0