dc_jt Posted May 16, 2007 Share Posted May 16, 2007 Hi what do I use to check if a directory contains anything. For example how do I check if there is anything in this? (Which in english is something like news/download/may2007/document1.doc UPLOADS_PATH.'/news/download/'.$oDownload->download_path.'/'.$oDownload->download Thanks Quote Link to comment Share on other sites More sharing options...
jitesh Posted May 16, 2007 Share Posted May 16, 2007 $files = glob("news/download/may2007/*"); if(count($files)){ echo "Available"; }else{ echo "Not Available"; } Quote Link to comment Share on other sites More sharing options...
taith Posted May 16, 2007 Share Posted May 16, 2007 this also works... <?php function file_emtpydir($dirname){ if(is_dir($dirname)){ $handle=opendir($dirname); while(($name=readdir($handle)) !== false){ if($name!="." && $name!=".."){ return false; break; } } closedir($handle); return true; }else return false; } ?> Quote Link to comment Share on other sites More sharing options...
dc_jt Posted May 17, 2007 Author Share Posted May 17, 2007 Hi I tried both of the above, but not getting any joy. I want to remove an image (which i have done), however I want it to check if there is anything else left in this folder and if not, then for the file to be deleted. This is the remove function I have: public function RemoveImage1($iNewsId) { $oObj = $this->GetObject($iNewsId); if ($oObj->image1) { unlink($_SERVER['DOCUMENT_ROOT'].UPLOADS_FOLDER_NEWS_LARGE.'/'.$oObj->image_path.'/'.$oObj->image1); unlink($_SERVER['DOCUMENT_ROOT'].UPLOADS_FOLDER_NEWS_THUMBNAILS.'/'.$oObj->image_path.'/'.$oObj->image1); //Think I need something here to delete the folder //$_SERVER['DOCUMENT_ROOT'].UPLOADS_FOLDER_NEWS_LARGE.'/'.$oObj->image_path $sSql = "UPDATE $this->sTableName SET image1 = '', image_path = '' WHERE $this->sPrimaryKey = '$iNewsId' "; return mysql_query($sSql, $this->oDb->GetConnection()); } return true; } Quote Link to comment Share on other sites More sharing options...
jitesh Posted May 17, 2007 Share Posted May 17, 2007 <?php $files = glob("news/download/may2007/*"); echo "<pre>"; print_r($files); ?> Check are you getting list of the files a folder may2007 contanning. Quote Link to comment Share on other sites More sharing options...
dc_jt Posted May 17, 2007 Author Share Posted May 17, 2007 I tried that and it had thumbs.db on the end? Quote Link to comment Share on other sites More sharing options...
jitesh Posted May 17, 2007 Share Posted May 17, 2007 that means there is a file thumbs.db in a folder may2007/ Quote Link to comment Share on other sites More sharing options...
taith Posted May 17, 2007 Share Posted May 17, 2007 windows blasteds image datafile... huge file, no point to it... Quote Link to comment Share on other sites More sharing options...
dc_jt Posted May 17, 2007 Author Share Posted May 17, 2007 Any other way then??? Quote Link to comment Share on other sites More sharing options...
neel_basu Posted May 17, 2007 Share Posted May 17, 2007 $files = glob("news/download/may2007/*"); if(count($files)){ echo "Available"; }else{ echo "Not Available"; } I am making a simple change on it <?php $files = glob("news/download/may2007/{*.jpg, *.gif, *png, *.JPG, *.GIF, *.PNG}", GLOB_BRACE);//Makes sure that it contains no Image if(count($files) < 1) { echo "Aviliable"; } else { echo "Not Aviliable"; } ?> Quote Link to comment Share on other sites More sharing options...
dc_jt Posted May 17, 2007 Author Share Posted May 17, 2007 Thanks a lot, that done it Quote Link to comment Share on other sites More sharing options...
neel_basu Posted May 17, 2007 Share Posted May 17, 2007 Please Click on the solved button on the bottom left now. 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.