+ 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
13 Antworten
+ 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
+ 1
I tried bt it store only 1 image at a time
+ 1
let us see the code, just part where you save the image
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 ;)";
}
?>
0
I try like this
0
Ok
0
what failed ? saving to folder part or the sql ?
0
Sql
0
Only one image store at a time and i want to store multiple images at a time
0
file_path isnt unique column right ?
or better, catch the error if there's any. by printing out mysql_error($conn)
0
Ok
- 1
Please don't post code as a plain text, save it in code playground and post it here.
- 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 ?