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
Calling a Function Within a Class Method
How to Implement a Bitmask in PHP
JSON VS. Serialized Array in Database
Laravel Validation Attributes "Nice Names"
How to Efficiently Use Try...Catch Blocks in PHP
Laravel:Migrations & Seeding for Production Data
Generating Confirmation Code for an Email Confirmation
How to Learn About PHP Internals
Is There Any Difference Between _Dir_ and Dirname(_File_) in PHP
Regular Expression Preg_Quote Symbols Are Not Detected
PHP Get Name of Current Directory
How to See the Extensions Loaded by PHP