PHP while loop to display images from MySQL [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a MySQL table storing images and a code which displays an image on the site.
$sql = "SELECT * FROM upload";
$sth = $db->query($sql);
$result=mysqli_fetch_array($sth);
echo '<img src="data:image/jpeg;base64,'.base64_encode( $result['content'] ).'"/>';
I want to display all images with a while loop.
Please don't tell me "Don't put images in your database" or something like that.

Your approach is wrong from the beginning! Saving as a blob type is not a good approach anymore as it just puts additional load on the database. Instead, what you should do is upload file to a specific folder on your hosting using:
move_uploaded_file($filetmp,$filepath);
Guide for move_uploaded_file
Then save the uploaded file path in the database.
After that, wherever you need to use the images get the path from db and in src of img echo that path.

Related

How to get image data from database mysql in react native [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have a problem, I am using backend with Codeigniter and upload the image to MySQL with varchar type.
This is the name of the image after I input:
and now I want to get that image to react native with fetch API, but how to get image from database to react native, because in MySQL just the name of the picture is saved? please help me
You have to save the file on the server's disk and filename name in your database. You'll have to know the location of your file so when you want to fetch it you'll have to build a full url to the file like http://example-domain.com/uploads/filename.jpg or you can save the full path in the database instead of just a filename. If you don't have a server to store the image you may consider saving the image blob into the database which I don't recommend.

Dynamic image slider using php and mysqli [closed]

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 6 years ago.
Improve this question
I do want to display image slider which is being uploaded by the admin to the slider using php and mysqli. If the admin wants to change the images he would be able to do it by uploading or deleting the images.
Add the image and display
Store the image in a folder by using move_uploaded_file()
Store the image name and path in database
Display it in html by using select query <img src="<?php echo $img; ?>" />
While modify the image
Select the image from database and remove it unlink($file)
Upload new image in directory and update the path in database.
Delete the image
Select the image from database and remove it unlink($file)
Delete the row from database.

How Should I store My User's Images? [closed]

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.

PHP insert image upload url in database [closed]

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.

Storing a file into a database & uploading it in a webpage [closed]

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 7 years ago.
Improve this question
Background
I'm creating a website where the user can store an article as a file in the database and than upload the file's content into a page in the website using a form. The file may only contain text or image or both.
Question
Can anyone walk me through this?
I would suggest you to create a database table having fields having the userId, and path of the file.
The file uploaded should be saved in the Web Server, and its path need to be saved in the database.
The vice-versa should be done while retrieving the file content.

Categories