How to save profile picture in php ? or How to save profile picture of User in Your application? or how to save images in Database?
This is what you are looking for ,you might be looking specifically for android,PHP,web app,iOS,Windows or whichever app it doesn’t matter. This article will help you in achieving that.
As you want to add profile picture in Profile system . It is required that you should have server. You can save the profile of user locally but it doesn’t make sense. Profile picture should be visible to everyone.
That’s why you need your server from where you can serve your users.
Setting up is not very difficult. You will just need to updates your domain name servers to the name servers provided by your hosting provider.
I will guide you step by step from here.
You must be having your database at your server. Now alter your table and add one column as pro_link or name you want. This is column where we’re going to save image attri.
ALTER TABLE table_name ADD column_name datatype;
Now you have just added column. Next is we will create a script in PHP . Which will be stored on your server. and we will call it using domain name.
Although having PHP script is not essential, You can use directly your server IP address. But problem here is that in case you upgrade your hosting or moved to another or hosted self server then . Your previous configurations are useless. This is why we required a domain.
I will suggest that for storing your Scripts you should create another subdomain . Which will make sense. Like
Now final , I hope that you are developing that kind of complex app. You must be added primary key in your user table. IF yes then Good. else Go and add primary key.
ALTER TABLE Persons ADD PRIMARY KEY (ID);
Now you have 3 ways to do that
May be late But I just found way to do that.
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
do in that style.
use other things to rename that image like user’s email,username etc.
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
here the url will be same in all columns excluding that hash key. you may only store that hashes.
To achieve way 3 you can generate hash. There are multiple ways to genrate hashes.
To generate MD5 hash from email
<?php /*Here techupdates.live is your password which you want to encrypt*/ echo password_hash("TechUpdates.live", PASSWORD_DEFAULT); ?>