Page 1 of 1

how to dymanic load image from directory into web page??

Posted: Sun Mar 07, 2010 10:33 pm
by Rickpo12
I am looking for direction as to how to accomplish this task. Here is what I would like to do:

1. I have a directory on my web server called images. In this directory I have files called 1.jpg, 2.jpg, ....1000.jpg.
2. I want to read the FIRST image in this directory into a webpage. The first time it will be 1.jpg, the next time the page is loaded it will be 2.jpg.
3. I want to allow the users to see this image and type in a new file name for this image and the click submit.
4. On submit I would like three things to happen on the server. 1. The image to be saved with new name in the image2 directory. 2. The original image to be removed from the image directory. 3. Load the next image in the image directory and give the user the ability to rename it.
5. This becomes a loop at this point.

Any pointers as to how I would accomplish this using php I would appreciate it.

Thank you all
Rickpo12

Re: how to dymanic load image from directory into web page??

Posted: Mon Mar 08, 2010 12:59 am
by maneetpuri
Hi,

Here is the logic that you will have to follow: -


a. Using the files & directory functions of PHP read the content of the directory. This will come as array.

b. Start a loop that will run from the first name in the array and go till last.

c. For every entry in this array you will have to ask user to enter a new name and then using the move command of PHP to move the image files from one folder to another and then use the unlink function to delete the old file.

d. Then show the next image to the user and repeat the step c

Make sure that both the folders source & destination for images have 777 permissions on them. In the source folder you might have to give 777 permission to all the images saved in it.

Hope this helps.

Cheers,

~Maneet

Re: how to dymanic load image from directory into web page??

Posted: Mon Mar 08, 2010 11:56 am
by Rickpo12
Question, just thinking out loud on this. I will probably have multiple people accessing this page and all will be working on renaming all the image filenames that reside in the directory until all images have been renamed. So with that in mind, meaning multiple users working on this project, would I want to read the directory contents into an array? What might be the preferred method to use to read the first or random image file from the directory each time the page is loaded until all images are gone? Or does this information not change the logic?

Thank you again php gurus.

Rick