图像在php中上传时不显示 [英] image not displaying when uploading in php
本文介绍了图像在php中上传时不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用一个非常简单的php页面上传文件并将图像显示在同一页面上;但是,图像不显示。我检查了图片是否正在上传以及在哪里,并且它正在上传到与php文件相同的目录。
< ;!doctype html>
< html>
< head>
< title>标题< / title>
< / head>
< body>
< h1>档案上载< / h1>
< form method =postaction =upload.phpenctype =multipart / form-data>
选择文件:< input type =filename =filenamesize =10/>< br />
< input type =submitvalue =upload/>
< / form>
<?php
//检查用户上传的图片
if($ _ FILES){
$ name = $ _FILES ['filename'] ['name ];
move_uploaded_file($ _ FILES ['filename'] ['tmp_name'],$ name);
echo上传的图片$ name< br />;
echo< img scr ='$ name'height ='100px'width ='100px'/>;
}
?>
< / body>
< / html>
解决方案
echo < img scr ='$ name'height ='100px'width ='100px'/>;
更改为:
echo< img src ='{$ name}'height ='100px'width ='100px'/>;
edit:在双引号中包含变量时使用大括号
请提供图片的完整路径,例如 http://www.example.com/path/to/image/image.png
I'm using a very simple php page to upload a file and display the image to same page; however, the image is not displaying. I checked whether the image was being uploaded and where, and it is being uploaded to the same directory as the php file.
<!doctype html>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>File Upload</h1>
<form method="post" action="upload.php" enctype="multipart/form-data">
Select File: <input type="file" name="filename" size="10" /><br/>
<input type="submit" value="upload" />
</form>
<?php
//checking if user uploaded image
if($_FILES) {
$name = $_FILES['filename']['name'];
move_uploaded_file($_FILES['filename']['tmp_name'], $name);
echo "Uploaded image $name <br/>";
echo "<img scr='$name' height='100px' width='100px'/>";
}
?>
</body>
</html>
解决方案
echo "<img scr='$name' height='100px' width='100px'/>";
change to :
echo "<img src='{$name}' height='100px' width='100px'/>";
edit: Use curly brackets when including a variable in double quotes.
And please provide whole path of the image, like http://www.example.com/path/to/image/image.png
这篇关于图像在php中上传时不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文