Image file path in Database

Why need to store image file path in mysql table when I know where my image resides(inside my xampp project folder). Each image has a unique name(numbers)

I can display the images with opendir,readdir functions right?

Kindly assist

Yes and no. In a database table, you store an image name as either a filename or a full path with filename.
If the filenames are in a logical format, then it is not needed. Not sure what your application actually does.

What I mean, is design of a system is step #1 ! ! ! Always! Let’s say you want to keep a list of users and let them upload
their pictures for their profiles and posts. Since you already have a table of the user’s with an ID in the table, you can just
rename the picture when storing it as ID#.jpg. So, the 3rd member that registers and uploads a pix would end up with a
filename of 3.jpg on their profile picture.

If you are using a security camera that saves the pictures in a certain format, like 2016-06-08:01:58:34 , then, you do not
need to save the filename in a table. It really depends on what you are doing…

Now, if you already have the pictures are all in the same folder, and you still need to save the filename, it is easy. Just save
them in a text field. You must decide if you save the full name with the extension or if you just need the name.

Not sure if this helps. So, it sounds like you have the files already. They are stored inside one folder. You can get those
names in PHP with ease! Let’s say the images are in “xampp/httpdocs/project1/images” and you want to display them all.
Something loosely like this would work:

$images = glob("xampp/httpdocs/project1/images/’.jpg’);
foreach ($images as $file) {
echo $file . “
”;
}
That script will show all your image filenames. Now, for the display part, you would need to display them as an image
not as a text filename. You would need to do it something loosely like: echo “”; instead.
(
** Note the quotes and double-quotes so the filename is quoted correctly! *** )

Well, hope all that helps!

Sponsor our Newsletter | Privacy Policy | Terms of Service