if(preg_match('/^[a-zA-Z0-9]+\.(gif|jpe?g)$/',$row['filename'],$matches) &&
is_readable($row['filepath'].$row['filename'])){
echo header('Content-Type: image/'.$matches[1]);
echo header('Content-Length: '.filesize($row['filepath'].$row['filename']));
echo file_get_contents($row['filepath'].$row['filename']);
} else {
echo 'cant serve image: '.$row['filename'];
}
当我尝试放置header('Content-Type': image/jpeg)
例如时,它只显示一个空白页面和当前 url。
我试图显示图像来替换我的<img>
标签。
filepath 包含图像目录的物理路径。