View Full Version : add photo into mysqol
ellenropa
9-30-07, 05:55 AM
How can I add photo into mysqol
Ellen
here some code to add photo to DB.
<?php
$file = $_FILES['upfile']['tmp_name'];
$size = $_FILES['upfile']['size'];
$data = mysql_real_escape_string (fread (fopen ($file, "r"), $size));
$query = "INSERT INTO photo (photo) VALUES ('$data')";
$result = mysql_query ($query) or die ("Query failed: " . mysql_error());
$photoid = mysql_insert_id();
?>
u can also use these link
http://www.phpriot.com/d/articles/database/images-in-mysql/index.html
a step by step Guide
groetjes
Neat Pete
9-30-07, 09:02 PM
When I read the link to php-riot, the first section of the article goes...
"Isn’t this a bad idea? This argument continues to rage and many lives have been lost trying to prove that this is a Bad Idea. The facts are, this method of binary storage is very successful and has many advantages over filesystem storage."
Back around 1997/98 I was involved in a database project where all the images were stored inside the database. In earlier times, Oracle had promoted this tactic as the best way to store all your corporate documents safely etc etc. Repository anyone?? In the next version of the database, around 1999, the files were stored as jpg files and only the names and folders were stored on the database. This has normally been the suggestion made by to posters to these forums.
At this very instant, the same database is running on a server in a Sydney technology park, with well over 5000 jpg files in about 200 folders, and a M$ SQL Server database.
Think carefully before you put your image content inside the database. Performance is fine, the problem is just duplication of the storage space - you still start with the jpg files, users will submit jpg files to you etc. Then you need the same space again inside the database.
If it grows to be big, you will need utilities to manage all the files and their sizes. These utilities could query the database of course, but in PHP, it's far simpler to look at the file system. Users are now submitting pictures straight out of the camera and have no concept that such an image is too big for the web. But the task is too big to fix manually. I'm glad I don't have the added complexity of having the images inside the server. Just resizing and making thumbnails from files is enough for today.
vBulletin v3.6.0, Copyright ©2000-2010, Jelsoft Enterprises Ltd.