简体   繁体   中英

how to save image from folder to database

$result=$db->query("SELECT * FROM Table WHERE id='2' ");
while($row = $result->fetch_array())  {
$id=$row["id"]; 
$URL=$row["URL"]; 
}

insert img to database MySQL:

$files_name = "folder/$URL";

#$files_name = "folder/img.jpg";

$fileSize = filesize($files_name);
$fType = filetype($files_name);
$fileName=$id;

$content = fread($fileSize);
$content = addslashes($content);
fclose($fp);

//

$Update ="UPDATE Table SET name_file='$fileName',size='$fileSize',type='$fType',content='$content' WHERE id='$id'";
$Up_ok = $db->query ($Update);

How to save image from folder to database?

I suggest, making a default path, where your system will store all images. Having this path, make a table with each ID designated to an image. In this table just store the image-ID and the ending of each picture path.

So if your picture is stores in path //server/common/images/image1.jpg You have default path '//server/common/images/' and each picture will have sth like 'image1.jpg'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM