hello,
i'm new in php & mysql. my prob is, i don't know how to upload existing image file to mysql database.
here the example.
existing image
$file = "/picture/user.jpg";
want to insert to mysql database.
can anybody help plsssssssssss
upload existing image file to mysql database
Moderator: General Moderators
Re: upload existing image file to mysql database
It is almost never a good idea to store images in the database. Never ever let the public do so. Better to store the images in a directory of the website and simply store the image name in the database. But since you asked, here is code that will accomplish what you THINK you want to do.
Then simply include $photodata in your INSERT statement.
Code: Select all
$uploadfile = $_FILES['upload']['tmp_name'];
$inst_photoname = $_FILES['upload']['name'];
$uploadtype = $_FILES['upload']['type'];
if ($uploadfile != "") {
$tempfile = fopen($uploadfile, 'rb');
$photodata = fread($tempfile, filesize($uploadfile));
$photodata = addslashes($photodata);