繁体   English   中英

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

[英]php glob and scandir function is not working on web server

我在我的网站上使用此glob函数不知道出了什么问题。在this.its上花费了太多时间。它在localhost上工作,但在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_mode ,您可能还会遇到问题。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM