php glob和scandir函数在web服务器上不起作用

php glob和scandir函数在web服务器上不起作用,php,mysql,Php,Mysql,我在我的网站上使用这个glob函数,不知道问题出在哪里。在这上面浪费了太多时间。它在本地主机上工作,但在Web服务器上不工作。请帮帮我 代码: $result = mysql_query($qry) or die ("Query failed"); $count=mysql_num_rows($result); $HTML=''; if($count > 0){ while ($friendList = mysql_fetch_array($result)

我在我的网站上使用这个glob函数,不知道问题出在哪里。在这上面浪费了太多时间。它在本地主机上工作,但在Web服务器上不工作。请帮帮我

代码:

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

正如@Emilio所述,尝试使用
readdir()
而不是
glob()
,特别是因为您并不真正需要glob()提供的模式识别

你能试试这个吗

// 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.';
}
一般性意见:

1.)对于@Emilio对mysql_*函数的评论,再加一个+1

2.)如果您在共享主机上运行脚本,由于启用了
safe_模式
,您也可能会遇到问题

3.)在使用ajax调用时检查错误:Firebug的网络面板将显示从服务器返回的响应,只需在调用时将其打开即可。如果服务器输出任何错误,您将在相应AJAX调用的响应选项卡上看到该错误


4.)关于代码:如果直接覆盖$image或$files等变量,则无需初始化它们,
$dir=…
末尾的两个双引号也已过时。我还建议您选择一种变量样式,最好是在$后面加一个小写字母的CamelCase语法。

我只需要该目录中的第一个图像。但在数组中,它不会在服务器上显示任何内容您确定设置了
$friendList['property\u Id']
,如果有任何
error\u报告(-1),请将其放在脚本的开头,以查看错误;ini设置(“显示错误”,真)$friendList['property\u Id']来自数据库。它返回正确的值。在php.ini中有两个选项,或者编写此
错误报告(-1);ini设置(“显示错误”,真)在你的脚本顶部我不知道我的朋友可能是什么问题,php的手册上说:
注意:在某些系统上,无法区分空匹配和错误。
尝试完成工作,阅读我尝试了这段代码,它打印“目录不可访问或不存在”但是我在folderFiles中有一些文件,您可以使用FTP看到这些文件,这并不一定意味着PHP进程的所有者可以看到这些文件。告诉我们一些关于您的生产服务器的情况,您是在托管它还是在共享主机上?如果您是通过FTP登录的,请尝试将该文件夹的目录权限设置为0755,以使每个人都能阅读。检查路径问题的另一个方法是:如果包含图像的目录可供web用户访问,请将包含
的文件上载到该目录并浏览到该文件,检查
服务器中返回的位置['SCRIPT\u FILENAME']
如果它与您试图在脚本中打开的目录匹配,则必须是访问权限。