我一直在尝试使用PHP上传包含html表单中其他属性的图像,下面的代码有点工作,但是当我从目录中选择文件后提交表单时。我可以在我的数据库BLOB列中看到该文件,但是我数据库的image_name列中的文件名是一系列我认为是Binary的字符。
请参阅下面的代码,任何建议都会有所帮助,而且我想在回声中显示保存的图像,如果可能的话,可以回显“
//connect to db
include 'connect.php';
//$random = rand(23456789,98765432);
$file = $_FILES['image']['tmp_name'];
if (!isset($file))
echo "Please select an image.";
else {
$image = addslashes(file_get_contents ($_FILES['image'] ['tmp_name']));
$image_name = addslashes ($_FILES['image'] ['name']);
$image_size = getimagesize($_FILES['image']['tmp_name']);
if ($image_size==FALSE)
echo "That is not an image.";
else
{
if (!$query = mysql_query ("INSERT into events VALUES ('','$event_type','$title','$description','$date','$location','$image_name','$image','$add1','$add2','$city','$postcode','$country','$tick')"))
echo "Problem uploading image";
}
}
答案 0 :(得分:0)
确保您的表单包含:enctype="multipart/form-data"
然后使用:
'move_uploaded_file($ _ FILES [“image”] [“tmp_name”],“uploads /”。$ _FILES [“image”] [“name”]);'