NoNameZ
NoNameZ

Reputation: 795

How to create folder in parent directory?

My php script is located in /var/www/html/users/dev. I need to create a folder in /var/www/images/ - something like /var/www/images/test/test/ and store here some images.

But when i trying is with mkdir($file_dir, 0777); where $file_dir is /var/www/images/test/test/ i receive an error:

Warning: mkdir(): No such file or directory in /var/www/html/users/dev/classes/sites.class.php...

Upvotes: 0

Views: 4349

Answers (3)

lotusphp
lotusphp

Reputation: 227

Because "/var/www/images/test" does not exists, so you can not mkdir("/var/www/images/test/test")

You can specify the "$recursive" to TRUE, and it will work, like this:

mkdir($file_dir, 0777, TRUE);

Upvotes: 9

user1595358
user1595358

Reputation:

if it is Linux you have set permissions to your parent directory 1st.

sudo chmod -R 777 /path of ur directory.

Upvotes: 1

GolezTrol
GolezTrol

Reputation: 116110

Try

mkdir($file_dir, 0777, true);

The third parameter ('recursive') allows you to specify a path of which all directories will be created. If you don't, only the last directory ('test') will be created, and the whole path before that must exist.

The PHP documentation is quite clear about that.

Upvotes: 1

Related Questions