Guest Posted March 7, 2008 Share Posted March 7, 2008 Im quite new to the php scene and am trying to develop my site using php.Got a few books and done a few tuts. But where i am stuck is, i need a script that can display on my site so say if a folder on my server has a file in it or not :S e.g if the folder has test.jpg in it the site will say folder full and if there is nothing in the folder to display folder empty. Hope ya's can help Many thanks Ma9ic. Quote Link to comment Share on other sites More sharing options...
Rohan Shenoy Posted March 7, 2008 Share Posted March 7, 2008 Use file_exists() function Quote Link to comment Share on other sites More sharing options...
Guest Posted March 7, 2008 Share Posted March 7, 2008 Thank you for you help , im nearly there but how would i use this if i dont know what the name of the file in the folder will be? Hope ya can help so thats me solved Quote Link to comment Share on other sites More sharing options...
moon 111 Posted March 7, 2008 Share Posted March 7, 2008 You can use this: <?php $dir = 'directory'; echo (count(glob("$dir/*")) === 0) ? "$dir is empty" : "$dit is not empty"; ?> Hope it helps Quote Link to comment Share on other sites More sharing options...
Guest Posted March 7, 2008 Share Posted March 7, 2008 Thanks job done, many thanks for you help Quote Link to comment Share on other sites More sharing options...
conker87 Posted March 7, 2008 Share Posted March 7, 2008 Would a function like the following work too? Might use this if it does. <?php directoryExists($dir) { return (count(glob("$dir/*")) === 0) ? "$dir is empty" : "$dir is not empty" } ?> 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.