2011-10-01 23 views
0

當我嘗試運行這個php腳本時,我在ssh中得到了以下響應......它在php 5.2下正常工作,現在已安裝5.3,我遇到了麻煩。我看不出什麼是錯的。PHP腳本現在在PHP 5.3下接收錯誤?

的錯誤:

線1:PHP:沒有這樣的文件或目錄

線2:鄰近意外的標記'0'

線2語法錯誤:`參數或者set_time_limit(0); 「

這是腳本。

<?php 
set_time_limit(0) ; 

$arr = explode("/",$_SERVER['SCRIPT_FILENAME']); 
$ct = count($arr); 
unset($arr[$ct-1]); 
$path=implode("/",$arr); 
$path=$path."/"; 

if(is_file($path."state.txt")) 
{ 
    $lines = file($path."state.txt"); 

    if($lines) 
     { 
     foreach($lines as $line) 
      { 
      if($line) 
       { 
       $state = trim($line); 
       if(!is_dir($path.$state)) 
        { 
        @mkdir($path.$state,0777); 
        if(is_file($path."copieble/state/index.php")) 
         { 
          $from = $path."copieble/state/index.php"; 
          $to = $path.$state."/index.php"; 
          @copy($from,$to); 
         } 
        } 
       } 
      } 
     } 
} 

@chdir($path); 
      $handle=opendir('.'); 
       while (($file = readdir($handle))!==false) 
        { 
        @chdir($path); 
        if (($file != ".") && ($file != "..")) 
         { 
          if(is_dir($file) && $file != "copieble" && $file !="_vti_cnf") 
           { 
           if(is_file($path.$file.".txt")) 
           { 
           $lines = file($path.$file.".txt"); 
             if($lines) 
              { 
              foreach($lines as $line) 
               { 
               if($line) 
                { 
                $city = trim($line); 
                @chdir($path.$file); 
                if(!is_dir($city)) 
                 { 

                  @mkdir($city,0777); 
                 if(is_file($path."copieble/city/index.php")) 
                  { 
                  $from = $path."copieble/city/index.php"; 
                  $to = $path.$file."/".$city."/index.php"; 
                  @copy($from,$to); 

                  } 
                } 

                } 
               } 
              } 
           } 

           } 

         } 
        } 
       closedir($handle); 
include("reflect_changes.php"); 
?> 

回答

3

我猜你正在運行像這樣:

./my_script.php 

嘗試這樣運行它:

php my_script.php 

第一會錯誤的原因是,當你嘗試像可執行文件一樣運行它,shell首先查看是否存在hashbang。如果是這樣,它會與該解釋器一起運行。如果沒有(就像你的情況),它會嘗試將它作爲可執行文件運行。這也失敗了,所以它試圖將它作爲一個shell腳本來執行。

<?php在shell腳本中將嘗試從一個名爲?php的文件開始讀取,並將其轉換爲後面的命令,但沒有名爲?php的文件可讀取。因此,它錯誤。

+0

lol忘了所有關於在shell中首先使用該php ...但現在我得到'無法打開輸入文件'... – user756659

+0

瞭解它 - 感謝指出愚蠢的錯誤...必須更多睡眠比我想象的要多! – user756659