为什么我上传的图片没有显示在我的php页面上?

时间:2013-05-03 06:59:18

标签: php html

以下是上传页面的主页:

<form id="form1" method="post" action="display.php" enctype="multipart/form-data" id="pro_image">
    <input type='file' onchange="readURL(this);" name="image" id="image"/>
    <br><img id="blah" src="profile pic.jpg" alt="your image" width="160px" height="120px"/><br/>
</form>

与图像显示页面(display.php)脚本合并:

<?php
 $dir="upload/";
 $name=$_FILES['image']['name']; 
 $tmp=$_FILES['image']['tmp_name'];
 move_uploaded_file($tmp,$dir.$name);

 ?>

 <br /><img src="".$dir.$name."" width="100" height="100"/>

任何人都可以帮我指出display.php上的实际问题并更正我的脚本?图片没有在页面上显示。

display.php的输出如上图所示: enter image description here

3 个答案:

答案 0 :(得分:4)

你忘记了<?php ?>

<img src="<?php echo $dir.$name; ?>" width="100" height="100"/>

答案 1 :(得分:1)

您的display.php文件是一个php文件,您尝试显示变量数据而不回显它在此文件中使用它。

<img src="<?php echo $dir.$name; ?>" width="100" height="100"/>

<强>编辑:

move_uploaded_file($tmp,$dir.$name) or die("There is error in uploading");

答案 2 :(得分:0)

  1. 首先检查你的图片是否在上传/文件夹中正确上传。上传图片的权限问题发生了变化。

  2. 然后检查通过提供URL手动访问图像 http://test.com/uploads/image1.jpg

  3. 如果所有这些调试都使用firebug在

  4. 中显示了什么路径
  5. 如果此路径错误,请尝试使用绝对路径而不是相对路径。

相关问题