这是我的代码。用户添加来自上一页的图像,然后由$ _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>
答案 0 :(得分:0)
您将在此处获取图像的二进制来源:
$image_1 = file_get_contents($_FILES['image']['tmp_name']);
然后在隐藏的字段中回显它:
<input type="hidden" name="image" value="<?php echo $img;?>" />
这段很可能来自该段。不确定为什么要包含它,tmp路径就是你真正需要的。