Laravel 4 - Storing unlimited filenames + image sizes - php

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.

Related

Good ways to implement multi sizes for thumbnails?

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.

How to add a text+image+text+image+ ... in mysql?

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..)

PHP image upload and showing

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.)

What's the best way of cataloging large number of images?

I'm looking at setting a site up with a large number of searchable images, organised by keywords, tags etc. I'm planning to get the image information from the IPTC data. The images will be uploaded by FTP then added into a database. My question is this:
Is there any advantage to storing the IPTC data in the database record for each image or just getting it from the file as and when it's needed?
My gut feeling is that it would be more efficient and easier to work with to have it all in the database but I'd like to make sure before I start to build anything.
I'd certainly put the data into database in some form. You can then ensure that it is indexed and is much faster to search. To get maximum benefit, you would need to preprocess the data into a format that is easy for the database to search. EG keywords should be stored individualy or coded as a many to many relationship (picture_ref, keyword_ref pairs) between the picture and a central list of keywords.

Best way to use MySQL for image galleries? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
What is the best way to store a series of images in MySQL?
This is the first website that I built for a friend a few months ago:
http://www.jpsinghphotography.co.uk
I want to rebuild it as my first PHP/MySQL project, but I had a couple of questions regarding how to structure the database.
1) Is it best to put the actual image files in the database using BLOB data types; or store the file names and use these to look up the images from another folder on the server?
2) I'm new to SQL and I'd initially imagined a seperate table for each gallery I want to create. In what ways is one table sorted by category better?
Thanks for any and all advice
Welcome to stackoverflow.
You can put image data in MySQL, but it's usually better to put them as files. That make them easier to cache and thumbnail, otherwise you have to do them yourself.
One table sorted by category would allow you more flexibility in category names and make it easier to move images between categories as well as get information from multiple categories such as image count of each category.
I would stick to providing a reference ie. the file name in the MySQL table. Putting the images in the table as BLOBs would mean you're now maintaining two copies of your pics. If you're primary application is to store history, this makes sense, but otherwise, a simple reference to the original is probably better.
A secondary issue may be storage space: you'd obviously be dealing with some very large tables if you BLOB the pictures. That may or may not be a problem.
As others posted, creating multiple tables for each gallery is a definite no-no and against the whole philosophy of using a relational database. Simple add a column to the pictures table that holds the gallery id and make it part of the unique key. You may also want a separate gallery table too, to be more 'normalized' about it.

Categories