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 Link to comment https://forums.phpfreaks.com/topic/51642-solved-check-if-a-folder-contains-anything/ 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"; } Link to comment https://forums.phpfreaks.com/topic/51642-solved-check-if-a-folder-contains-anything/#findComment-254395 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; } ?> Link to comment https://forums.phpfreaks.com/topic/51642-solved-check-if-a-folder-contains-anything/#findComment-254405 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; } Link to comment https://forums.phpfreaks.com/topic/51642-solved-check-if-a-folder-contains-anything/#findComment-255271 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. Link to comment https://forums.phpfreaks.com/topic/51642-solved-check-if-a-folder-contains-anything/#findComment-255278 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? Link to comment https://forums.phpfreaks.com/topic/51642-solved-check-if-a-folder-contains-anything/#findComment-255281 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/ Link to comment https://forums.phpfreaks.com/topic/51642-solved-check-if-a-folder-contains-anything/#findComment-255283 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... Link to comment https://forums.phpfreaks.com/topic/51642-solved-check-if-a-folder-contains-anything/#findComment-255285 Share on other sites More sharing options...
dc_jt Posted May 17, 2007 Author Share Posted May 17, 2007 Any other way then??? Link to comment https://forums.phpfreaks.com/topic/51642-solved-check-if-a-folder-contains-anything/#findComment-255292 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"; } ?> Link to comment https://forums.phpfreaks.com/topic/51642-solved-check-if-a-folder-contains-anything/#findComment-255294 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 Link to comment https://forums.phpfreaks.com/topic/51642-solved-check-if-a-folder-contains-anything/#findComment-255299 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. Link to comment https://forums.phpfreaks.com/topic/51642-solved-check-if-a-folder-contains-anything/#findComment-255304 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.