传输图像数据时显示随机输出


Random ouput is displayed when tranferring image data

这是我的代码。用户从前一页添加图像,然后由$_FILES收集并在该页中处理。奇怪的是,当有人添加图像时,我得到一个由随机数和符号组成的大随机段落,显示在这个页面上。我不知道这是哪来的。任何想法吗?

如果你们好奇的话,底部的表单会将所有信息重定向到另一个页面,然后添加到数据库中。

  <?php
        $file = $_FILES['image']['tmp_name'];
        if(isset($file))
        {
            $image_1 = file_get_contents($_FILES['image']['tmp_name']);
            $image_name = $_FILES['image']['name'];
            $image_size = getimagesize($_FILES['image']['tmp_name']);         
        }
        if ($image_size===FALSE)
        {
            die("That is not an image. Please go back and choose and image.");
        }

  $title = $_POST['title'];
  $author = $_POST['author'];
  $isbn = $_POST['isbn'];
  $price = $_POST['price'];
  $location = $_POST['location'];
  $class = $_POST['class'];
  $description = $_POST['description'];
  $contact = $_POST['contact'];
  $img = $image_1;
  $img_name = $image_name;

  if(!$title || !$author || !$isbn || !$price || !$location || !$class || 
          !$description || !$contact)
  {
      echo "You have not entered all the required details.<br/>"
      ."Please go back and try again.";
      exit;
  }
  ?>
    <h1>This is what will be submitted</h1>

    <?php
    echo <<<_END
    <pre>
        Title: $title
        Author: $author
        ISBN: $isbn
        Price: $price
        Location: $location
        Class: $class
        Description: $description
        Contact Information: $contact
        Your Image :
            If this is correct, please press sumbit. If you would like to
            make changes, go back and make them
    </pre>
 _END;
?>
    <form action='PSBE_INSERT_AD.php' method='post' enctype="multipart/form-data"/>
    <input type="hidden" name="title" value="<?php echo $title;?>" />
    <input type="hidden" name="author" value="<?php echo $author;?>" />
    <input type="hidden" name="isbn" value="<?php echo $isbn;?>" />
    <input type="hidden" name="price" value="<?php echo $price;?>" />
    <input type="hidden" name="location" value="<?php echo $location;?>" />
    <input type="hidden" name="class" value="<?php echo $class;?>" />
    <input type="hidden" name="description" value="<?php echo $description;?>" />
    <input type="hidden" name="contact" value="<?php echo $contact;?>" />
    <input type="hidden" name="image" value="<?php echo $img;?>" />
    <input type="hidden" name="image_name" value="<?php echo $img_name;?>" />
    <input type="submit" value="Ad Post" />
    </form>
</body>

您将在这里获得图像的二进制源:

$image_1 = file_get_contents($_FILES['image']['tmp_name']);

然后在这里的隐藏字段中输出:

<input type="hidden" name="image" value="<?php echo $img;?>" />

这很可能是这段话的来源。不确定为什么要包含它,tmp路径是您真正需要的。