Page 1 of 1
upload image into mysql table through php
Posted: Wed Nov 30, 2005 4:54 am
by dude81
Hello
How to upload an image into mysql table
what could be the possible query I write it?
is it possible to bind the image variable??
Posted: Wed Nov 30, 2005 5:13 am
by onion2k
Upload the image file as you would any other file, get the contents using file_get_contents(), and insert the data into a BLOB field.
It's not really a good way to store images though .. the overhead is much greater than just storing the filename in the database and saving the file into a directory somewhere.
Not sure what you mean by "is it possible to bind the image variable??".
Posted: Wed Nov 30, 2005 5:55 am
by dude81
what can be the possible query if I assume there are two fields(one field is image and the other field is to identify the image)
I checked the
viewtopic.php?t=40543
but Im doing some thing like this
Get the uploaded image directly into mysql database through mysql query
when Im prinitng
Code: Select all
$lob_upload = $_FILES['lob_upload'];
Array ( [name] => Dscf0007.jpg [type] => image/jpeg [tmp_name] => /tmp/phpCweDQX [error] => 0 [size] => 42970 )
which one of this I assume to be the complete image
Posted: Wed Nov 30, 2005 8:04 am
by dude81
No One...

Posted: Wed Nov 30, 2005 8:41 am
by shiznatix
i don't know if the file exists on the server yet when its just in $_FILE but you should seriously reconsider saving a image to a database. if you are still all about it, just do the actual upload to the server, then file_get_contents the location of the uploaded file, then insert that into the database (remember the field has to be type BLOB) then unlink() the uploaded file. very inefficient but thats the only way i know of doing it.
Posted: Wed Nov 30, 2005 8:49 am
by onion2k
Code: Select all
$image = file_get_contents($_FILES['lob_upload']['tmp_name']);