+ 2

How to store multiple image in my sql using php?

I am creating project online shopping using html n php in this i want to save multiple image at same time n move those another folder and save those image in my sql database please help me fo solve this as soon as possible i have to submit it tomorrow please help

17th Oct 2019, 11:36 AM
chandni Sorathiya
13 Réponses
+ 1
you technically can save image data in binary, either using blob or base64 format. but i dont recomend that, the size could get bigger really easily, and query start slowing down. on a extreme case it would crash the database. recomended way is as Aymane Boukrouh said, save it in folder. and save the path to that image to the database
17th Oct 2019, 11:55 AM
Taste
Taste - avatar
+ 1
I tried bt it store only 1 image at a time
17th Oct 2019, 11:57 AM
chandni Sorathiya
+ 1
let us see the code, just part where you save the image
17th Oct 2019, 11:59 AM
Taste
Taste - avatar
0
<?php $conn = mysql_connect('localhost','root',''); mysql_select_db('ocs'); for($i=0;$i<count($_FILES['file_img']['name']);$i++) { $filetmp=$_FILES["file_img"]["tmp_name"][$i]; $filename=$_FILES["file_img"]["name"][$i]; $filetype=$_FILES["file_img"]["type"][$i]; $filepath = "IMAGE/".$filename; move_uploaded_file($filetmp, $filepath); $sql="INSERT INTO demo_image (img_path,img_name,tag,p_id) VALUES ('$filepath','$filename','','')"; $r = mysql_query($sql); echo "done ;)"; } ?>
17th Oct 2019, 12:17 PM
chandni Sorathiya
0
I try like this
17th Oct 2019, 12:18 PM
chandni Sorathiya
0
Ok
17th Oct 2019, 12:21 PM
chandni Sorathiya
0
what failed ? saving to folder part or the sql ?
17th Oct 2019, 12:44 PM
Taste
Taste - avatar
0
Sql
17th Oct 2019, 12:45 PM
chandni Sorathiya
0
Only one image store at a time and i want to store multiple images at a time
17th Oct 2019, 12:46 PM
chandni Sorathiya
0
file_path isnt unique column right ? or better, catch the error if there's any. by printing out mysql_error($conn)
17th Oct 2019, 12:49 PM
Taste
Taste - avatar
0
Ok
17th Oct 2019, 12:50 PM
chandni Sorathiya
- 1
Please don't post code as a plain text, save it in code playground and post it here.
17th Oct 2019, 12:21 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
- 2
Why save images in a database at all ? Just keep them in a separate folder. But if your project says you should, then I don't know, maybe try and store the images as a binay or color codes in your sql ?
17th Oct 2019, 11:44 AM
Aymane Boukrouh
Aymane Boukrouh - avatar