开发者

Why can I not create a directory using php?

开发者 https://www.devze.com 2023-02-16 01:02 出处:网络
I have a form where users can upload an image. I have another page which already works that then creates a directory and places the image in it. For some reason, when I copy that same code to my curre

I have a form where users can upload an image. I have another page which already works that then creates a directory and places the image in it. For some reason, when I copy that same code to my current page, it gives me the following error:

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

Here is the code it is referring to:

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

I tried echoing out all those variables, so I know they work.

It seems pretty straighforward to me, so i'm not sure why the mkdir function isn't working for me on this page. Any ideas anyone?


Using mkdir with two parameters, in order to create the directory a/b/c, the directory a/b must exist.

If you want a/b to be created when you try to create a/b/c, you need to pass true as a third parameter (the one called recursive ;-) ) to mkdir.


If you upload directory already exists, then, you need to make sure that ../upload/ is actually what you think.

This ../upload/ is relative to the current directory of execution (which is not necessarily the same as the one that contains your script !)


You might want to try using this :

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

to check if that directory is what you think -- it'll display its full path if it exists ; or false if it doesn't.


you are passing wrong path to the function man.

i.e move_upload_file($arg);

If u give wrong path in $arg,it will show the error msg as u said.

0

精彩评论

暂无评论...
验证码 换一张
取 消