How Should I store My User's Images? [closed] - php

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I've been reviewing all sorts of ways and researching, but I haven't been able to find solutions. Should I store them in my host's database, my filesystem, or through a third party? If through a third party, which one? Imgur, AWS S3, etc?

The best way is to store the images' location on the database and then link it via PHP or ASP from some protected directory.
Example (when you are saving picture name and extension with extension):
Query to select all data:
PHP:
{ $profile_picture = $row['pictureLocation']; }
Then wrapping around the path to directory:
$profile_picture = "../assets/protected/images/users/" . $profile_picture ;
HTML:
<img src="<?php echo $profile_picture ; ?>" >

Usually the easiest way (space allowing) is to simply store the actual picture file in your filesystem. Then, in order to reference the file, store the file path in a MySQL database. With that said, there are many ways to store pictures and the best is to experiment with them.

Related

PHP insert image upload url in database [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I have two way for insert image upload url in MySQL database:
One:(only filename)
1410468094_shutterstock_130757219.jpg
Two:(full url)
http://localhost/nws/uploads/files/1/shutterstock_130757219.jpg
which way is better?
file name is best cause if anytime you change folder name or location .
Second way without the domain name is batter. I mean uploads/files/1/shutterstock_130757219.jpg is batter. Because your domain name may change over time. But you should put the file path relative to your web root directory.
If all images will be put in the same folder you would like to leave out the path, that way you could move the images one day to S3, CDN or anywhere else and won't have to update all the records. However if the images comes from all over the Internet, you need the full path.

Best practice for saving images with unique filename [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
What is the best method to save uploaded images on my php server?
Say i have a database of works with an an image.
Should I add a random string to prevent overwriting other images?
Should I create a folder with the unique Id of the work?
what's the best way?
Completely up to you. A timestamp is always useful as unless you're uploading more than one image per second, they're guaranteed to be unique.
Chuck in any unique IDs, user IDs, attribute IDs etc.
e.g. < user_id >_< attribute_id >_20150219235959.jpg
I prefer file name + date time
$removeExtension = explode('.',basename($_FILES["fileToUpload"]["name"]);
$target_file = $target_dir .$removeExtension[0].date("m-d-y").date("h-i-sa").".$removeExtension[1]"); //renamin the file to the current time as e.g. cover_02-03-15-01-13-18pm.jpg
My approach would be adding the upload time on the file name:
$time = date('his');
$filename = $originalfilename."_".$time.".jpg";

suggestion for the way for storing multimedia belong to different users [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
What's the best way more scalable way to do that.
Currently my database is Mysql and i am using php in my website. But It is just a demo. But I want to ensure the way i store multimedia resource is scalable with manageable accessibility.
The simple way is storing links in database of multimedia.
Another way is creating specific folder for each user's multimedia and put the media in his or her own folder.
And Some other simple way. But I need an expert's suggestion.
Any other Suggested architecture would be appreciated!
If you know link, website, Publication which can help me let me know.
Create separate folder and store multimedia in the folder. For detailed answer follow these links:-
Storing Images in DB - Yea or Nay?
Storing images in DB vs in Folder Structure

Application Editable Settings (Best Practices) [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am looking for the best way to store the application editable settings (ex: Site Name, Is the site closed? .. etc).
It seems like Database is not the best way because I don't want to use a database just for 2 or 3 settings!
So I went to PHP Array but how can I edit it?!
I have reviewed all questions related to this, but I can not find a useful answer for me.
Note: I don't want to edit the settings manually. I want to edit it by php.
You can store the settings in a config file in form of serialized array or JSON.
Say, reading settings:
$settings = json_decode( file_get_contents('settings.cfg') );
Saving settings back:
file_put_contents('settings.cfg', json_encode($settings) );
Of course the file should be writeable permission wise.
You can store anything you want in this array, even simple objects and complex arrays. And as it is JSON you can edit the file manually, too. If a need arises.

Is there special reason why online services often store images with semi random name [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
In real practice we see user uploaded image with name like 84b222882da311e284b222000a1fbcf6_7.jpg
Isn't it much easier and structured to just store image as
/username/101.jpg
/username/102.jpg
(For example you can have a database table for images and you can then simply use the index as file name.)
What are the practical consideration here? I guess one would have to check every time whether a newly generated random name is not in the database? Is there concern about obfuscation?
Typically it's done for two reasons.
To have unique filenames.
Makes it difficult to guess image filenames (stops people from just entering the next image in the URL and seeing the image).
Isn't it much easier and structured to just store image as /username/101.jpg /username/102.jpg
Not at all. That way requires a directory listing to get the highest number used, and presents issues with deletions - do you reuse the ID? 101.jpg and 102.jpg are at least as arbitrary as 84b222882da311e284b222000a1fbcf6.jpg, which is likely a hash of the file content or the file's ID in the database.

Categories