make sure your form has: enctype="multipart/form-data"
then use:
'move_uploaded_file($_FILES["image"]["tmp_name"],"uploads/" . $_FILES["image"]["name"]);'
Pergunta
I have been trying to upload an image including other attributes in a html form using PHP, the code below sort of works but when i submit the form after choosing the file from a directory. I can see the file in my database BLOB column but the name of the file in the image_name column of my database is a series of characters which I think is Binary .
see Code below any suggestions will be helpful and also I would like to display the saved image in an echo something like echo '' if that is possible
//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";
}
}
Solução
make sure your form has: enctype="multipart/form-data"
then use:
'move_uploaded_file($_FILES["image"]["tmp_name"],"uploads/" . $_FILES["image"]["name"]);'