2017-09-25 101 views
-1

我想指向我的目錄,但不知道我該怎麼做?使用php的點目錄文件夾

我的腳本是這樣的:

if(is_dir('./anotherfolder/'.$schedule['folder'])) { 
      $schedules[$key]['files'] = array(); 
      $files = scandir('./anotherfolder/'.$schedule['folder']); 

這索引文件是在這個目錄folder/index.php英寸 我想指出它anotherfolder/page1.php

這意味着我必須退出文件夾,回去再進入另一個文件夾

+1

您可以在PHP中使用'..'父文件夾選擇。 – rickdenhaan

+0

像這樣我得到了一堆錯誤'is_dir('../ anotherfolder /'.$ schedule ['folder']' –

+1

這是正確的方法,請添加錯誤,你得到你的問題 – rickdenhaan

回答

0

可以使用__DIR__代替..像這樣:

if (is_dir(__DIR__.'/anotherfolder/') { 

當你在folder/index.php

或者你可以使用file_exists檢查PHP文件是該文件夾中:

if (file_exists(__DIR__.'/anotherfolder/page1.php') { 
+0

像這樣沒有工作'$ files = scandir(__ DIR __。'。/ anotherfolder /'.$ schedule ['folder']' –

+0

不要在路徑中的文件夾前添加一個點,只需使用'/ antoherfolder / – divix