Jump to content

Images: blob or...


dakke

Recommended Posts

it not right to store images in your database.. I suggest instead of inserting images in your db just store the location of each images.. so you only need to call those images.

Link to comment
Share on other sites

it not right to store images in your database.. I suggest instead of inserting images in your db just store the location of each images.. so you only need to call those images.
^^^^^ listen to him
Link to comment
Share on other sites

thats why you rename the file when you upload it(usually using uniq_id(),time() and some hashing function). And if a user uploads files, then you could just create a directory based on their username(which would be unique) and just upload photos from there, checking to see if a the file exists already with the same name, if so, tell the user they must rename the file and then use move_uploaded_file etc etc.

Link to comment
Share on other sites

  • 2 weeks later...
It's not necessarily wrong to store files in a database, if that's what the application requires. If you want to store binary data a blob is the best type to use.
An application that needs to match text in one column to the image in another column, for instance? If so, is that what a 'blob' is for?
Link to comment
Share on other sites

Blob is for any binary data, it stands for binary large object. But in most cases it is a better solution to store the file on disk and store the filename or path to the file in the database, you incur a performance penalty when you need to get the binary data from the database and output it.

Link to comment
Share on other sites

That, and it makes it ###### for the poor guy who has to look at the code after you. I know if i saw a bunch of BLOB column types with image data i'd probably quit and tell them to get a different person.

Link to comment
Share on other sites

It's really not that bad. If the data is messed up there's nothing you can do about it, but assuming they put it in the database correctly it's as easy as using file_get_contents to store something and it's a small script that gets it back out of the database and recreates the file. e.g.:

<?phpinclude 'db.php';$result = mysql_query('SELECT image FROM table WHERE id=' . intval($_GET['id']));$row = mysql_fetch_assoc($result);header('Content-type: image/jpeg');header('Content-disposition: attachment; filename=image.jpg');header('Content-length: ' . strlen($row['image']));echo $row['image'];?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...