bemax Posted May 7, 2009 Share Posted May 7, 2009 Hi I'm working with php in my project at school. Now I have a problem, it's a system where I want the administrator to chose a logo from his computer and submit it. Then show it when registed persons login. I'm using Mysql - and I want load images in my database. Can someone help me with this code? Or if there is an other way I can get it help please! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/157226-send-images-to-databasemysql-then-show-them/ Share on other sites More sharing options...
Ken2k7 Posted May 7, 2009 Share Posted May 7, 2009 You can't load an image to the DB. You just put it into a folder and put the name of it in the DB for reference. Quote Link to comment https://forums.phpfreaks.com/topic/157226-send-images-to-databasemysql-then-show-them/#findComment-828690 Share on other sites More sharing options...
bemax Posted May 13, 2009 Author Share Posted May 13, 2009 Can you tell me please how to do it? Quote Link to comment https://forums.phpfreaks.com/topic/157226-send-images-to-databasemysql-then-show-them/#findComment-833388 Share on other sites More sharing options...
drew7721 Posted May 15, 2009 Share Posted May 15, 2009 Hello bemax! I'm not an expert, really not but maybe this can help... Iwas trying to do the same thing not to long ago and it's true it's easyer to save the directory path as varchar but if you really need to you can make a BLOB instead of a VARCHAR and there you can save raw pictures or pdf files to later recuperate from your website. here is a little script that worked for me be4 but really slows down database. I can't really explain it to you but a fast google search for mysql blob should get you going. $file = fopen ($_FILES["userfile"]["tmp_name"], "rb" ); //get temp size $size = filesize ($_FILES["userfile"]["tmp_name"]); //read temp file $content = fread ($file, $size); //protects by / / $userfile = addslashes ($content); $sql = "INSER INTO image (image) VALUES ("'{$userfile}'" )"; @mysql_query ($sql, $connection); // gets picpour recuperer l'image $sql = "SELEC * FROM image WHERE image_id=".$id_image; $result = mysql_query ($sql, $connection); if (mysql_num_rows ($result)>0) { $row = @mysql_fetch_array ($result); //gets bontent in binary mode $image = $row["image"]; //shows pic echo $image; there are a lot of codes out there that can help you out! hope you get a good grade Quote Link to comment https://forums.phpfreaks.com/topic/157226-send-images-to-databasemysql-then-show-them/#findComment-834445 Share on other sites More sharing options...
Thauwa Posted May 15, 2009 Share Posted May 15, 2009 This would help you a lot. http://php.about.com/od/phpwithmysql/ss/Upload_file_sql.htm PM me if you want the code which I edited to make the images be viewed individually. P.S. I am on a schooler too Quote Link to comment https://forums.phpfreaks.com/topic/157226-send-images-to-databasemysql-then-show-them/#findComment-834684 Share on other sites More sharing options...
Cardale Posted May 16, 2009 Share Posted May 16, 2009 well technically you could load the image into the database, but that's more work then what is necessary. Quote Link to comment https://forums.phpfreaks.com/topic/157226-send-images-to-databasemysql-then-show-them/#findComment-835487 Share on other sites More sharing options...
BK87 Posted May 17, 2009 Share Posted May 17, 2009 you have to upload image as blob to mysql... its easier to store in folder.... less stress of mysql server Quote Link to comment https://forums.phpfreaks.com/topic/157226-send-images-to-databasemysql-then-show-them/#findComment-835655 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.