【问题标题】:Check file type using php scandir not working使用 php scandir 检查文件类型不起作用
【发布时间】:2016-06-19 21:51:09
【问题描述】:

我正在使用下面的 php 来检查保存在数据库中的文件类型,但是它将所有内容显示为文件夹,我不知道问题是什么。

<?php
$path = dirname(__FILE__);
$sub_folder = scandir($path);
$num = count($sub_folder);
//$jailchillink This is the name of file saved in database replaced width index.php
    if(is_file($path.'\\'.index.php)){  $codetype = 'file';}
   else if(is_img($path.'\\'.index.php)){  $codetype = 'image';}
    else{ $codetype = 'folder';}?>

上面的代码会输出folder

【问题讨论】:

  • 调试:使用echoprint_r在每行代码后显示每个变量或函数调用的内容。这样您就可以轻松找出问题所在。

标签: php image file directory


【解决方案1】:
<?php
  $path = dirname(__FILE__);
  $sub_folder = scandir($path);
  $num = count($sub_folder);
  //$jailchillink This is the name of file saved in database replaced  width index.php
  if(is_file($path.'\\'.'index.php')){
     echo $codetype = 'file';
  }else if(is_img($path.'\\'.'index.php')){
    echo $codetype = 'image';
  }else{ 
    echo $codetype = 'folder';
  }
?>

现在输出是file。只需在index.php 周围添加'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-02
    • 2018-07-23
    • 2011-08-02
    • 1970-01-01
    • 2010-10-11
    • 2018-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多