upload image into mysql table through php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

upload image into mysql table through php

Post 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??
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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??".
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post 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

User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

No One... :( :cry:
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Code: Select all

$image = file_get_contents($_FILES['lob_upload']['tmp_name']);
Post Reply