1

i am using this glob function on my website dont know what is the problem.wasted too much time on this.its working on localhost but not working in webserver. please help me

code :

 $result = mysql_query($qry) or die ("Query failed");
    $count=mysql_num_rows($result);
    $HTML='';
    if($count > 0){
    while ($friendList = mysql_fetch_array($result))
     {

     $_SESSION['PropertyId'] = $friendList['property_Id'];
     $Username = $friendList['UserName'];
     $qry1 = "SELECT Mobile_Number1,FirstName FROM registration WHERE UserName = '".$Username."'";
    $result1 = mysql_query($qry1) or die ("Query failed");
    $friendList1 = mysql_fetch_array($result1);
    $mobNo = $friendList1['Mobile_Number1'];
    $Name = $friendList1['FirstName']; 
    $image = "";
    $dir = "propertyImages/".$friendList['property_Id']."";
    $files = array();
    $files = glob("$dir/*.*");
    $image = "";
    print_r($files);
    if (count($files) > 0) 
    {
    $image = $files[0];
    }
    else
    {
    $image = 'img/1.jpg';
    }
dvirus
  • 201
  • 2
  • 21

1 Answers1

0

As @Emilio stated, try readdir() instead of glob(), especially because you are not really needing the pattern recognition glob() does provide.

Could you give this a try?

// enable error reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');

// initialise empty $files array
$files= array();

if (file_exists($dir)) {
  $dh= opendir($dir);
  if ($dh) {
    while ($file= readdir($dh)) {

      // skip "." and ".."
      if ($file != "." && $file != "..") {
        echo "$file\n";
        $files[]= $file;
      }
    }
    closedir($dh);
  } else {
    print 'Directory handle could not be opened.';
  }
} else {
  print 'Directory not accessible or does not exist.';
}

General comments:

1.) another +1 for @Emilio's comment about mysql_* functions

2.) If you are running your script on a shared host you may also experience problems due to safe_mode being enabled.

3.) Checking for errors when using ajax calls: Firebug's Network panel will reveal the response returned from the server, just have it open while doing the call. If any error is output by the server you will see the error on the Response tab of the corresponding AJAX call.

4.) Regarding code: you don't need to initialise variables like $image or $files if they are directly overwritten, the two double quotes at the end of the $dir = ... are also obsolete. I would also recommend to decide for one variable style, best would be CamelCase syntax with a lowercase letter after the $.

SaschaM78
  • 4,376
  • 4
  • 33
  • 42
  • i tried this code it prints "Directory not accessible or does not exist" but i have files in that folder – dvirus Jan 11 '14 at 05:02
  • Files that you see using FTP which does not necessarily mean the owner of the PHP process does see. Tell us a bit about your production server, are you hosting it or is it on a shared host? If you are logged in via FTP, try to set the directory permissions on that folder to 0755 to make it readable by everyone. – SaschaM78 Jan 11 '14 at 09:58
  • Another idea to check path issues: if the directory containing the images is accessible for web users, upload a file containing `` to the directory and browse to that file, check the location returned in `SERVER['SCRIPT_FILENAME']` if it matches the directory you try to open in your script. If they are identical it has to be access permissions. – SaschaM78 Jan 11 '14 at 10:03