-2

I have a bit of a problem. I am putting up a profile picture on my system where the pictures are stored in a file and I'm calling it from the database. What I want to happen is this:

For person who haven't uploaded their picture yet, I want the system to open a certain directory that will serve as a default profile picture. So, my code goes like: it checks the the files if there is an uploaded picture IF NOT IT WILL OPEN A CERTAIN DIRECTORY.

<?php
  $profquery = "select User_ID from tusers where vName ='".$_SESSION['SESS_vName_JO'] ."' ";
  $search = mysql_query($profquery);

  $row=mysql_fetch_assoc($search);
  $q=$row['User_ID'];


  $dir= "../../profpic/" . $q . "/";
  $profimge=(count(glob($dir)) === 0) ? 'Empty' : 'Not empty';
    if(profimge=="Empty"){
  $pimge  = opendir($profimge);
  $files = array();
  while ($pfiles[] = readdir($pimge));
  natsort($pfiles);
  closedir($pimge); 
  foreach ($pfiles as $pfile)
    { 
      if ($pfile == "." || $pfile == ".." || $pfile == "thumbs.db" || $pfile == "Thumbs.db" || $pfile == "")
      {
        //skip
      }else
      {
        $profImage = "../../profpic/" . $profpic . "/" . $pfile;
        $pathofimage = "../../profpic/" . $profpic . "/";
      }
    } 
  }else if($profimge=="Not empty"){
    $folder = 0;
    $default = "../../profpic/". $folder. "/";
    $pimge  = opendir($default);
    $files = array();
    while ($pfiles[] = readdir($pimge));
    natsort($pfiles);
    closedir($pimge); 
    foreach ($pfiles as $pfile)
      { 
        if ($pfile == "." || $pfile == ".." || $pfile == "thumbs.db" || $pfile == "Thumbs.db" || $pfile == "")
        {
          //skip
        }else
        {
          $profImage = "../../profpic/" . $profpic . "/" . $pfile;
          $pathofimage = "../../profpic/" . $profpic . "/";
        }
      } 
    }
?>

My first code goes like this and it doesn't work too.

<?php


$profquery = "select User_ID from tusers where vName ='".$_SESSION['SESS_vName_JO'] ."' ";
$search = mysql_query($profquery);

$row=mysql_fetch_assoc($search);
$profpic=$row['User_ID'];

$cntImage=0;
$cStatus="";
$FName=$profpic;

$profimge= "../../profpic/" . $profpic . "/";
if(file_exists($profimge)){
$pimge  = opendir($profimge);
$files = array();
while ($pfiles[] = readdir($pimge));
natsort($pfiles);
closedir($pimge); 
  foreach ($pfiles as $pfile)
    { 
      if ($pfile == "." || $pfile == ".." || $pfile == "thumbs.db" || $pfile == "Thumbs.db" || $pfile == "")
      {
        //skip
      }else
      {
        $profImage = "../../profpic/" . $profpic . "/" . $pfile;
        $pathofimage = "../../profpic/" . $profpic . "/";
      }
  } 
}else{
  $folder = 0;
  $default = "../../profpic/". $folder. "/";
  $pimge  = opendir($default);
  $files = array();
  while ($pfiles[] = readdir($pimge));
  natsort($pfiles);
  closedir($pimge); 
  foreach ($pfiles as $pfile)
    { 
      if ($pfile == "." || $pfile == ".." || $pfile == "thumbs.db" || $pfile == "Thumbs.db" || $pfile == "")
      {
        //skip
      }else
      {
        $profImage = "../../profpic/" . $profpic . "/" . $pfile;
        $pathofimage = "../../profpic/" . $profpic . "/";
      }
    } 

}
?>
TheTruth
  • 25
  • 8

1 Answers1

0

Check if directory is empty function

public static function isEmptyDir($dir){ 
     return (($files = @scandir($dir)) && count($files) <= 2); 
}
siddhesh
  • 563
  • 1
  • 9
  • 15