簡體   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