如何编辑这个PHP脚本?如果文件存在显示这个,如果没有显示另一个?

时间:2014-02-24 10:54:00

标签: php ajax

如果文件.xls不存在,我需要编辑此脚本以显示页面的另一部分。例如$ found = false,show flashexit.php

    <?
     $page = $_SERVER['PHP_SELF'];
     $sec = "30";
     $find = '/flash/file/FLASH.xls'; //The file to find
     $paths = explode(PATH_SEPARATOR, get_include_path());
     $found = false;
     foreach($paths as $p) {
       $fullname = $p.DIRECTORY_SEPARATOR.$find;
       if(is_file($fullname)) {
         $found = $fullname;
         include($_SERVER["DOCUMENT_ROOT"]."/inc/flashnewblu.inc.php");
         break;
       }
    }
  ?>

2 个答案:

答案 0 :(得分:2)

我认为您需要检查此link。与函数file_exists

相关

答案 1 :(得分:1)

您可以使用内置函数file_exists检查文件是否存在:

<?php
 $find = '/flash/file/FLASH.xls'; //The file to find
 $paths = explode(PATH_SEPARATOR, get_include_path());
 $found = false;
 foreach($paths as $p) {
   $fullname = $p.DIRECTORY_SEPARATOR.$find;
   if(file_exists($fullname)) {
     $found = $fullname;
     include($_SERVER["DOCUMENT_ROOT"]."/inc/flashnewblu.inc.php");
     break;
   }
}
if(!$found) {
    echo 'File '.$fullname.' doesn\'t exists. Make a redirection to flashexit.php';
}
?>