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";
Related
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 11 days ago.
Improve this question
My goal is to add pictures inserted by user into a database. So I'm trying to set their names to the date of their creation. The format is "day.month.year hour.minute.second". But I'm facing the problem that the only one picture is added to the catalog. I'm thinking that the reason why it happens is because the script runs too fast for a second to pass.
And that made me think if this is a good idea to name pictures this way.
I started to assume that maybe I need to use some kind of library to manually add a second to every next picture's name.
But before doing that I decided to go ask somebody more profecient than me in order to undesrtand whether I need to do it this way or maybe there's a better one
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.
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.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
i want to be able to upload multiple images (i got this working) its array
only problem is i need each image to have its own content but i want to use one form as this relates to a specific article.As you see this picture
This welcome article for example has a heading, an image and text to explain for each image .
this is my current db structure but as you can see there is no way content will be separate for each image
article id is the foreign key
How could i achieve this in a database structure?
You talking about uploading images to your server right ? if so:
You got few options to do it:
Create a 'unique' id and put them inside the image element and the content element.
Then you will get two arrays and you combine them by the unique.
Almost the same, just simply to store the content and the images inside arrays. and just loop through them and 'combine' them by the array's id. because you inserting the same amount so it should be the same. But answer 1 is safer here.
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.