使用php scandir检查文件类型不起作用

时间:2016-06-19 21:51:10

标签: php image file directory

我正在使用这个下方的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

1 个答案:

答案 0 :(得分:0)

<?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