2011-03-11 107 views
0

我有一個表單,用戶可以上傳圖片。我有另一個已經工作的頁面,然後創建一個目錄並將圖像放入其中。出於某種原因,當我複製相同的代碼,以我目前的網頁,它給了我下面的錯誤:爲什麼我不能使用php創建一個目錄?

Warning: mkdir() [function.mkdir]: No such file or directory in /home5/ideapale/public_html/amatorders_final/user_char_upload.php on line 251

這裏是它指的是代碼:

if (!file_exists("../upload/" . $order_id . '_' . $row['last_name'])) { //Checks if the directory already exists 
    mkdir("../upload/" . $order_id . '_' . $row['last_name'], 0755); //Creates a new directory with the order_id and Customer last name 
} 

我想呼應了所有這些變量,所以我知道他們的工作。

對我來說這似乎很直接,所以我不知道爲什麼mkdir函數不適合我在這個頁面上工作。任何想法的人?

回答

3

使用mkdir有兩個參數,爲了創建目錄a/b/c,目錄a/b必須存在。

如果你想a/b當您嘗試創建a/b/c被創建,你需要通過true作爲第三個參數(一個叫recursive ;-))mkdir


如果upload目錄已經存在,那麼,你需要確保../upload/實際上你認爲是。

../upload/相對於執行的當前目錄


你可能想用這個來試試(這是不一定相同包含腳本的一個!):

var_dump(realpath('../upload/')); 

檢查該目錄是否是你的想法 - 如果它存在,它將顯示它的完整路徑;如果沒有則爲false。

+0

謝謝!這解決了這個問題,但現在我得到這個錯誤:[function.move-uploaded-file]:無法打開流:HTTP包裝不支持可寫連接 – zeckdude 2011-03-11 12:34:03

+0

You''re welcome :-) ;;那麼,這是另一個問題:你正試圖將文件移動到遠程位置,或類似的東西? *(最終,因爲這是一個明顯的問題,您可能想要問一個不同的問題,代碼示例和所有)* – 2011-03-11 12:35:28

0
you are passing wrong path to the function man. 

即move_upload_file($ arg);

如果你在$ arg中給出錯誤的路徑,它會顯示錯誤消息,如你所說的。

相關問題