readfile函数以非ASCII字符返回文件内容

时间:2015-03-28 10:52:03

标签: php html

当我执行以下代码时,图像不会显示在浏览器中,而是显示非ASCII符号和字符。很少的行如下:

  

JFIF6Photoshop   3.08BIMgqarIDeY1blFS2krGbsOU��ICC_PROFILElcmsmntrRGBXYZ�)9acspAPPL���-lcms   说明^ CPRT \ wtpthbkpt | rXYZgXYZbXYZrTRC @ GTRC @ BTRC @ descc2textFBXYZ    ���-XYZ3�XYZo�8��XYZb����XYZ   $����curv��c�k�?Q4!�)�2;�FQw]�kpz���|�i�}���0����C! $(   %2%(, - / 0 /#484.7 ./ç

我在这里做错了什么?

<?php
session_start();

if (isset($_SESSION['logSyscuruser'])) {
// logged in
$id = $_SESSION['logSyscuruser'];


$imgLocation = '/Applications/XAMPP/im/';

include "include/specificproductDB.php";
$data = new specificPro();

  $out = $data->select($query, $id, $pId);
  $count = count($out);


}

else
{
  //not logged in
header("Location: loginSystem/login.php", true, 302);
die();
}



?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" 
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="content-type">

    <link rel="stylesheet" href="css/main.css" type="text/css" />
    </head>
<body>
<div id="section">
<div id="header">
 <h1>Heading</h1>
</div>
  <p>
<?php
if($count==0)
{
    echo "Nothing added till now.";
}

else
{

for ($x = $count-1; $x >= 0; $x--)
  {

   if(strlen($out[$x][0]) == 68)
   {
    //file is detected
    $imgPath = $imgLocation . $out[$x][0];

    // Make sure the file exists
    if(!file_exists($imgPath) || !is_file($imgPath))
    {
        header('HTTP/1.0 404 Not Found');
        die('The file does not exist');
    }

    $imgData = substr($out[$x][0],65,3);

    // Set the appropriate content-type
    // and provide the content-length.
    header('Content-type: ' . $imgData);
    header('Content-length: ' . filesize($imgPath));

    // Print the image data
    readfile($imgPath);
    }

   else
   {

    header('HTTP/1.0 403 Forbidden');
    die('Fatal Error: Absurd entry in the database media table');
   }

   echo "<br><br>";

   }

  }

  ?>
  </p>

    <input type="button" value="Add Media" onclick="window.location = 'addMedia.php';">    

</div>



</body>
</html>

0 个答案:

没有答案