djpic Posted March 7, 2008 Share Posted March 7, 2008 Ok, here is what I want to do. I want to be able to read the contents of a directory with php. Here is exactly what I am AIMing for: Upload (FTP) a group of images to a directory on the server. Then, create a php code that will go through that directory giving me the full directory location (i.e. /home/test/photos/imagefile.jpg) for each file. That is the first task. The second task is for the program to find any subdirectories in that file. Once the program is finished reading the file names from the main directory, it goes to each of the sub-directory and finds all the files in those directories. My goal is to upload a group of pictures and then have a loop tag going through each of the photos, adding the information to a MySQL database, compress them, and copy them to a different folder. Please note though, I know how to do everything but getting the program to read the files in the directory. Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted March 7, 2008 Share Posted March 7, 2008 lookup the glob() function Quote Link to comment Share on other sites More sharing options...
djpic Posted March 7, 2008 Author Share Posted March 7, 2008 That is a nice function Northern Flame. And can see how I can use that in some other apps I am writing, thank you for that. I could also use that just to pull the .jpg files, this way there is no chance I pull a .doc and try to process that. Have to give that some thought. I was able to find this little bit of code which seems to the trick, the only thing is what happens when I have a sub-directory? <?php if ($folder = opendir('/home/photoshop/rawphotos/')) { while (false !== ($file = readdir($folder))) { echo "$file\n"; } closedir($handle); } ?> Could someone explain to me how the false !== ($file = readdir($folder)) works? Does the ($file = readdir($folder)) just return a true value if there is a file and a false value if there isn't? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.