How to Find a Reason When Mkdir Fails from PHP

How to find a reason when mkdir fails from PHP?

You can suppress the warning and make use of error_get_last():

if (!@mkdir($dir)) {
$error = error_get_last();
echo $error['message'];
}

distinguish what caused mkdir error

Sure, just check if the directory exists using is_dir() once mkdir() fails.

This will tell you if the directory exists, however it may not be conclusive, as permissions might also prevent you from checking this (I believe the parent directories need the +x permission in order to traverse into subdirectories).

mkdir() says theres no such directory and fails?

You have an error in your string:

mkdir("images/listing-images/rent/'.$insertID.");

should be:

mkdir("images/listing-images/rent/$insertID");

mkdir fails in every way

Instead of given url path http://www.mysite/uploads/images/1 you need to given relative path of folder like

$upload_dir="/var/www/html/your_folder";// path of your folder

mkdir($upload_dir, 0777);

mkdir only works on The directory path

PHP: run mkdir and get errno

You're probably looking for proc_open, which gives you the ability to work directly with stdin, stdout and stderr as PHP streams, meaning you can use the normal file reading and writing functions on them.

Please be sure to read more details about the proc_ family tree on the proc_close and proc_get_status pages.

You might have more luck working with the text of the error as provided to stderr instead of working with exit codes.



Related Topics



Leave a reply



Submit