Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php获取图像并在html中显示_Php_Html - Fatal编程技术网

使用php获取图像并在html中显示

使用php获取图像并在html中显示,php,html,Php,Html,我知道这是一个很简单的问题,但最终它不起作用,我是一个新手。在index.html中,swf发送一个图像,displayImage.php(下面的代码)应该在另一个页面上显示它。为什么它不起作用 <?php if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) { $no=0; while (file_exists("images/$no.jpg")) $no++; header('Content-Type: image/jpeg'); $

我知道这是一个很简单的问题,但最终它不起作用,我是一个新手。在index.html中,swf发送一个图像,displayImage.php(下面的代码)应该在另一个页面上显示它。为什么它不起作用

<?php
if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) {
$no=0;
while (file_exists("images/$no.jpg"))
     $no++;
header('Content-Type: image/jpeg');
$image = $GLOBALS["HTTP_RAW_POST_DATA"];
file_put_contents("images/".$no.".jpg", $image);
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml2/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-9" />
<title>Your Image</title>
<link href= "style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="logo"></div>
<div id="body"></div>
/////////display image//////////
<img src="images/<?$no.".jpg?>"> 

</body>
</html>

你的形象
/////////显示图像//////////
"> 
“>

这可能就是问题所在。“显示图像”注释下方的行可能应为:

<img src="images/<?= $no ?>.jpg"> 
.jpg>

您没有
回显
文件名(并且您有引用错误,但这可能是输入错误):

.jpg/>

假设存储文件确实有效。

我删除了行“header('Content-Type:image/jpeg');”并且它有效

可能是因为您使用的是XHTML。IMG标记不能像在普通HTML中那样打开。您必须以/>结尾。(当您出错时,它应该会灾难性地失败,但只有当您发送正确的MIME类型头以将其视为XML时,它才会失败,因此将其视为文本,您可能会得到不可预知的结果……)。如果它正在打印文件名(如images/1.jpg),那么您知道它正在正确解析内联PHP….

不能在脚本块之外使用
$no
。为什么不能?您是指while循环,因为它上面声明了$no,所以它是不相关的,还是因为它不在内部.jpg“>可以在xhtml中工作,但它不是。它只是打印php文件的名称。如http://mySite.rosenhost.info/displayImage.php?name=displaySWF.jpg
<img src="images/<?= $no ?>.jpg"> 
<img src="images/<?php echo $no ?>.jpg" />