Reputation: 8985
I don't know which way is better to use about uploading and saving a file in my local server. for example I see someone that INSERT image's link in the mysql field, I'm confused right now... I want to upload some files and show that in other situation... what's the best and secure way to perform that?
Upvotes: 2
Views: 3125
Reputation: 719
Store all the images in a folder called photos
for example. Then, save an index of the file in your database assigning it an index number and other information. Save the file in the photos folder, renaming it [index_number].jpg
, or whatever extension is needed. For example, if I upload the file coolpic.jpg
, it will be assigned an index number of 2845. The file itself is saved in photos/2845.jpg
.
Upvotes: 3
Reputation: 1507
Saving in Database may make some problems like as DB performance decrease (as result of reading and writing big files), DB crashes (as a result of delete of edits of rows fields), backup problems (because of huge dump file, some problems when table needs to be repaired. also read file from mySQL will be delivered by Apache again. I suggest you use of normal path with rewrite mode (virtual url)
Upvotes: 1
Reputation: 684
Dont use img link.. its not necessary and all it does is just making you DB larger.
You shoud store just "picture.jpg"
and in documents use <img src="images/'.$row['image'].'">
Even better, you can create a function for it (displaying pictures).
Like
function DImage($image)
{
//you can do miracles here like checking images types, if is file and so on, padding, even adding divs and vspaces..
$output = '<img src="imagesfolder/'.$image.'">';
return $output;
}
so latter all you have to do is.. echo DImage($row['image']);
PS: if you ask about $_POST & $_FILE uploading, of course.. it is impossible for you to maintain images, names and updates I'm sure..
Upvotes: 0