Skip to content
Advertisement

Images are upload in folder via form but name in DB is not image name. Instead it’s a path to XAMPP tmp file?

In my admin table, the column image is showing this path after the image uploads: C:xampptmpphpC6DA.tmp but image name don’t. Image is perfectly uploaded to desired folder and that is ok…

I’ve tried to change varchar to text, for image column in MySQL. Maybe it’s a XAMPP setting I don’t know? MySQL is set as InnoDB.

This is a part of the code

$img              = $_FILES['image']['name'];
$img_tmp          = $_FILES['image']['tmp_name'];
move_uploaded_file($img_tmp, "upload/$img");

$db->query("INSERT INTO admin (id, full_name, email, password, gender, image) VALUES (NULL, :full_name, :email, :password, :gender, :image)");

$db->bindvalue(":full_name", $name, PDO::PARAM_STR);
$db->bindvalue(":email", $email, PDO::PARAM_STR);
$db->bindvalue(":password", $pass, PDO::PARAM_STR);
$db->bindvalue(":gender", $gender, PDO::PARAM_STR);
$db->bindvalue(":image", $img_tmp, PDO::PARAM_STR);

$db->execute();

Advertisement

Answer

Replace

$db->bindvalue(":image", $img_tmp, PDO::PARAM_STR);

With

$db->bindvalue(":image", $img, PDO::PARAM_STR);

$img contains the name you want.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement