Jump to content

[SOLVED] Check if a folder contains anything


dc_jt

Recommended Posts

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

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;
}
?>

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;
}

$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";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.