0

我有一个文件,用户可以在其中查看其存储的文件。我希望只有登录用户,并且只能由存储该文件的成员查看。当我查看其他文件(如 . .html ,. txt等。但是当我查看任何图像时,它不起作用。

这是我的脚本:

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

如何查看图像?

4

0 回答 0