我试图读取一个图像文件(确切地说是.jpeg),然后"回显"它回到页面输出,但是显示图像...
我的index.php有一个像这样的图像链接:
<img src='test.php?image=1234.jpeg' />
Run Code Online (Sandbox Code Playgroud)
我的PHP脚本基本上这样做:
1)读取1234.jpeg 2)echo文件内容... 3)我有一种感觉我需要用mime类型返回输出,但这是我迷路的地方
一旦我搞清楚了,我将一起删除文件名输入并将其替换为图像ID.
如果我不清楚,或者您需要更多信息,请回复.
有没有办法从PHP中的SPL自动加载器中抛出异常,以防它失败?它似乎不适用于PHP 5.2.11.
class SPLAutoLoader{
public static function autoloadDomain($className) {
if(file_exists('test/'.$className.'.class.php')){
require_once('test/'.$className.'.class.php');
return true;
}
throw new Exception('File not found');
}
} //end class
//start
spl_autoload_register( array('SPLAutoLoader', 'autoloadDomain') );
try{
$domain = new foobarDomain();
}catch(Exception $c){
echo 'File not found';
}
Run Code Online (Sandbox Code Playgroud)
当调用上面的代码时,没有异常的迹象,而是我得到一个标准的"致命错误:类'foobarDomain'在bla中找不到".并且脚本的执行终止.