Efficient way to upload images in a post for a blog? - php

I was wondering a method to upload images in the posts of a blog. I am thinking of two ways:-
1) To create a row in the database for imageurl and use this url to point to the image stored on the local disk.
2) Is there a way to upload images directly to mysql???

You could use BLOB to store image directly in your database, But it makes your database heavy and usually all hosting services put a limit on database sizes.
I faced the same issue a while back and after some research i found out that The best way is to store it your file system and store its url in your database.
If you only have one folder, you don't need to store the whole URL just the file name and append the domain when displaying it.
Hope its help. :)

Related

laravel issue when upload images to s3 and store the paths in database

I am new the this PHP things
and I wanna create a article model which has title and some images
what I can do is save the title to my database
but not the uploaded images , even more , I don't know how to upload multiple images with php or should I call laravel ?
one single image is fine with me and I know the callback will tell me the image address but what indeed should I do to store them in database and relate them in the specific article model ?
many many thanks
Ok let me address this issue, your uploaded image should be renamed using timestamp reason is to avoid name collision. Look at this for example
$filename_path = md5(time().uniqid()).".jpg";
This ensures that you will always have unique name for the file.
Once you rename the file and move to s3 then you save $filename_path into a table.
During retrieval you get the name and search your s3 bucket for the image.
Hope this helps

How do i properly store and retrieve an image file path in phpmyadmin?

I am currently working on a personal stylist app using the codeigniter framework. I would like to display a list of items with their corresponding picture stored in my phpmyadmin database. I have researched about this and i found out that it is best practice to store only the file path of the image instead of storing the image directly in the database. I was just wondering if you guys could help me on how to do this properly. Thanks in advance!
Store relative path to your image. For example if the image is located on http://www.example.com/uploads/images/picture.jpg, keep only /uploads/images/picture.jpg in database

How do profile pictures work?

I'm using PHP and MySQL, and don't know where to start with how to set up profile pictures.
It seems all other user data can be held in the mysql table, but I don't think I can put pictures into a mysql table. So how do profile pictures generally work?
You can put pictures in a database (using a BLOB field), but I wouldn't, due to the performance hit.
Store the images on the filesystem with PHP, and just store the ID of the picture in the database.
I think that what is usually done is set up an upload system for users to upload their images. You just have to link this image with the user by naming it with something like a user ID.
Then you just have to store a link to the uploaded picture in your database, this way you could also imagine allowing user to use remote images although this might not be a good idea.
But as said, the MySQL BLOB field allows storing pictures.

how to make a gallery wherein the images used are from mysql database?

i just wanna ask on how to make a simple gallery for my website wherein the images used to display are from database and will automatically display on the gallery? so that when i have to update the images i won't enormously create thumbnails..??
I would recommend against keeping the image data in a database, it's almost always a bad idea.
I would recommend storing metadata about the images in the database and then including a pointer to the file (the image's path on the local filesystem). If you need to make thumbnails create them as the images are added, store them on the filesystem too and store the path to them in the table too.
Another approach is to have the filename of the image and thumbnail as a function of the image ID. E.g. store it on the server at /some/directory/images/123.jpg and /some/directory/images/123_thumbnail.jpg where 123 is the id of the image.
use mysql BLOB storage - Example: http://www.anyexample.com/programming/php/php_mysql_example__image_gallery_%28blob_storage%29.xml
You can create the thumbnails and update the database when the images are uploaded to a directory within your http path. A simple php routine can extract the picture names from the db and include them in your gallery.

How to create user-accounts' separate folders to save user data in--PHP

How would I save each user's 'default photo' onto a website? This same photo may be used during some of their interactions on the site(maybe in a chat session), and it may be displayed on their profile page. Will each user have their own folder? If so, how can I create such a folder. Will this folder stay on ftp? Or MySQL? Will it take any space? As of now, whatever photos are uploaded onto the server, are simply stored in a folder that reads--'uploadportrait.php'. Where can I go from this? If someone can tell me the general principles of this, then that would be great! Thank you in advance.
If it is just one photo it doesn't make much sense to create a folder for each user. If you already have a working upload routine, simply store the file path of the uploaded file inside of the user database. You don't need to duplicate the image then.

Categories