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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

$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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.