[英]php glob and scandir function is not working on web server
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. 我在我的网站上使用此glob函数不知道出了什么问题。在this.its上花费了太多时间。它在localhost上工作,但在web服务器上不工作。 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';
}
As @Emilio stated, try readdir()
instead of glob()
, especially because you are not really needing the pattern recognition glob() does provide. 如@Emilio所述,请尝试使用
readdir()
而不是glob()
,尤其是因为您实际上并不需要glob()提供的模式识别。
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 1.)@Emilio关于mysql_ *函数的注释的另一个+1
2.) If you are running your script on a shared host you may also experience problems due to safe_mode
being enabled. 2.)如果您在共享主机上运行脚本,由于启用了
safe_mode
,您可能还会遇到问题。
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. 3.)使用ajax调用时检查错误:Firebug的“网络”面板将显示从服务器返回的响应,只需在执行调用时将其打开即可。 If any error is output by the server you will see the error on the Response tab of the corresponding AJAX call.
如果服务器输出任何错误,您将在相应的AJAX调用的“响应”选项卡上看到该错误。
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. 4.)关于代码:如果直接覆盖$ image或$ files这样的变量,则无需初始化,
$dir = ...
末尾的两个双引号也已过时。 I would also recommend to decide for one variable style, best would be CamelCase syntax with a lowercase letter after the $. 我还建议您确定一种变量样式,最好是$后面带有小写字母的CamelCase语法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.