【发布时间】:2013-11-11 20:19:47
【问题描述】:
我正在尝试通过 php 脚本将图像提供给 html。但我被卡住了,它不工作:-( 下面是我的 image.php 脚本
<?
$_GET['f'] = 'all_three.jpg';
$image = null;
$image = file_get_contents($_GET['f']);
header("Content-Type: image/jpeg");
echo $image;
?>
下面是我的 index.html
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<title>Page Title</title>
</head>
<body>
<img src="image.php" alt="Image" />
</body>
</html>
图像链接在 php 中是“硬编码”的,我所做的只是调用“image.php”来提供该硬编码图像,但它不起作用!我做错了什么?
【问题讨论】:
-
您遇到了什么错误?你有正确的路径名吗?图片真的存在吗?
-
您是否尝试过直接访问 image.php 以查看它是否按预期工作或显示一些错误?
-
index.html,image.php, all_three.jpg 在我的 htdocs/testwebsite/ 中
-
当你尝试直接打开图片url时会发生什么?您还可以使用浏览器的调试工具查看图像的 http 请求,看看发生了什么。
-
@user2959229 我尝试直接访问“image.php”,它是一个空白页面。