如何在php上传后显示图像? [英] How to display image after upload in php?

查看:101
本文介绍了如何在php上传后显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

。如何显示图像..

我的upload.php

its my upload.php

<?php
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 20000000000000000000000)
&& in_array($extension, $allowedExts))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br>";
    echo "Type: " . $_FILES["file"]["type"] . "<br>";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"]."<br>";

$image=$_FILES["file"]["name"]; /* Displaying Image*/
      $img="upload/".$image;
      echo '<img src= "upload/".$img>'; 

      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>

图片上传正常。但图像没有显示。只显示一个小盒子。

the image is uploading fine. but the image is not displaying. a small box only showing.

此部分不起作用...

this part not working...

/* Displaying Image*/
       $image=$_FILES["file"]["name"]; 
              $img="upload/".$image;
              echo '<img src= "upload/".$img>';

上传成功后如何显示图片?

how to display the image after upload success?

推荐答案

我已经尝试过您的代码并且其工作正常需要更改行

I have tried your code and its working finely just need to change the line

echo'<img src= "upload/".$img>'; 

echo'<img src="'.$img.'">';

这篇关于如何在php上传后显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆