Thanks for jumping by!
I'm building a PHP script to manage employees, and I would like to get your help in deciding which good way do you use to implement multiple size for profile picture thumbnail.
The sizes may change (would like to keep it dynamic), thus, I can't set a specific column name for each thumbnail size.
I assume there are few options:
I can create a database table for each profile picture, there I will save the thumbnail path and "bind" to the user id with a foreign key, then I will be able to get all profile pictures and sort them based on my needs.
I can generate a thumbmail and save its path in the "users" table in a special column called "thumb_path" or something similar - in the same way I can store instead json of the profile picture paths (while the key represent the thumbnail size).
But both seems to be a bit wierd for me, and I can't clearly thing about another way to implement in efficiently.
Will be happy to get your kind help!
Marco.
I suggest to create one table for the thumbnails, with a reference to the user_id, the thumb path and the info about the size. You can have multiple rows for a user.
Hope this will help you.
Related
I have posts system where users can upload images inside a post, I intend to build the images paths url and not store the uploaded images paths in database.
I will simply use unique Post ID to build the url path for post images like:
$path = "images/{$postID}/";
Then when rendering the post I will use
$images = glob($path);
When post is deleted I will simply:
unlink($path);
Why all implementations for php image uploads that I read about contains table to store images paths? Why not this method are there any disadvantages that I am not aware about?
I think that this one can go with a little discussion. Although the image location is recommended to be stored in the database, but it is not always the best way. If you according to your logic find some algorithm to uniquely name images based on blog id or something that would save you database latency cost.
For the same i would like to give example of a sample use case. You are either way fetching blog text from database. Now you can add another field to store the number of images that you have associated with the same. Now take the unique id of blog suppose uq1. If that blog has 6 images , you can name the images as
$path = $uq1.$imageindex
remember that you will also have to store the image in same path. You can always get fancy and add simple XOR encrypt. Although the use of XOR is mainly when you are also associating sensitive data to the same. This will save you some database latency.
Hope this helps
its a good idea doing it in this way.
unless you don't need duplicates of a lot of images
for example if you have image apple.jpg with size 500K,
and you have 2000 posts that should have apple image in them.
so you will save 2000 x 500k of apple image.
but if you have it in the database and you just select images from
something as gallery so you will have only 1 image for apple.jpg
but it linked for 2000 posts using the database table.
but if you dont care! about duplicates and data size, or you are sure that there is no any post have any image like the other! so its ok.
summary: saving all post images in folder with its id is the easy way
but it will cost you space ( duplicates and so on )
the other way, saving the image link in database and just link it with every post need it. its better.
I am developing a chat application for iOS.
In this app, the users can set up an image as their profile picture.
So my question is, how can i be able to store images in mysql ?
I have seen that many people say, just store the link to the image(on device) in mysql, but how will the images be available on different iOS Devices, from a database right ?
I have also tried using BLOB, but when the table rows are displayed(json encoded), the value for BLOB field comes out to be NULL.
Please answer in brief.
Thanks,
This is fairly simple :) The physical image will be stored on a server and you will store in your DB only the image name, or the relative path to the image, or however you want it. So, if you like, you will have to store in your DB a "pointer" to that image.
So:
- Image in folder on the server
- In DB -> path/to/file or file_name.format OR if you know you path, and you know your format just file_name
Hope this helps! :D
May be late But I just found way to do that.
Way 1: Get image from user and rename with the id (Pref. Primary key) and in Your public_html create folder for images. Set proper permissions for that folder. and save image in that folder and the url of that image will be stored DB column . Like
https://www.example.com/images/user1.png do in that style.
Way 2: use other things to rename that image like user's email,username etc
way 3: In above 2 cases it may happen that other users,hackers may try to download images by using IDs,emails etc.
That's why , another way you can do is you can generate a hash for profile and check if the hash already exists in column if exits then generate another one. Likely I don't think there is possibility of generating similar hashes.but you may check to avoid error in future. and now rename image using that generated hash.
You may also reduce size of that link column using only storing generated hash and in your app declare some variables and achieve
https://www.example.com/images/generated_hash.png
here the url will be same in all columns excluding that hash key.
you may only store that hashes.
Hope it will help
Reference from : https://www.techupdates.live/how-to-save-profile-picture-in-php-in-5-simple-steps/
I was wondering if someone could help me out.
Im in the middle of writing migrations for a project, im a bit of a newb.
What i want to be able to do is store a gallery on each row of a table.
I have the following fields.
id
imagecount
displayimage
timestamps
The question i have is .... How would i be able to store varying amounts of imagenames + the sizes of those images in a field.
As im not going to be able to know how many images are in each gallery i have to be able to store varying amounts on the fly.
What would be the best way of doing this?
Any help would be greatly appreciated.
Cheers
If you want to store images in single table then you have to use JSON. In JSON you can have varying amount of images as separated indexs.
Although you have to spend more coding effort to add or remove images from gallery
Other solution would be to use a 2-table based approach. Where you need table structure like this
Gallery <id,added , other stuff ..>
Images <id,gallery_id,name,size, other stuff ..>
Its really straightforward. Store images in Images table.Link them using Primary-Foreign-Key relation with Gallery table.
I'm using php for scripting. My typical problem is how do I add a question in mysql which has a lot of alternate text and images. Imagine something like a description from Organic Chemistry which has those benzene structures.
What's the most efficient way to do this? I understand that if I had a single image I can add an url to that image in the database.
It may be poor but i do it this way in my projects. You can create another table in your database.Let me explain this:
Text...Image...Text
You can handle this by this steps:
Create a table that will be post_meta
Insert every image into this table and every image should have a post id
In the other table(actual post table) store your post something like this:
Text...{MetaImage}....Text
When printing your post if you replace your tags with the image paths in the table post_meta, you could handle this.
By this way:
1. You will not store long and dirty image src's in the post table.
2. Your all media contents will be in a table.(image,music,video etc..)
First sorry I'm a big beginner.
Would like to ask a more experienced developers opinion.
I have small website a really small social network for sports, and I would like to allow the users to create image folders and upload multiple images there.
As I was reading through the internet, they say that it is bad to store the images in the database, only save the location of the image.
But this is the part what I don't understand, more precisely the logic what I don't really understand.
I go to the users profile select the folder, but what is the way to show the images?
Is it a good idea to select the folder and use scandir to get the images? And if I'm scanning the folder is it possible to limit it to, for example, limit it to only one image at first what points to the gallery?
And I was thinking to separate the location path table in the database tied to the user ID, won't that be a problem? Won't that make the database really large?
Sorry if these are stupid questions, I would just really like to know.
Now I don't want anybody to write this for me, just give an opinion about the logic.
Thank you.
I would recommend you to store all information about the folder and pictures in the database.
For example a schema like the one in the diagram below. The advantage of having the data in a database is that you can get as many pictures as you want. And later you can add additional information to the table (e.g., permission for other users, comments, etc.)