Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php create directory

Tags:

php

I am creating a directory and I am getting the error

Warning: chmod() [function.chmod]: No such file or directory in /home/www/public_html/console/pubs-add.php on line 104

The php file that is running the code is in www/console and the directory that I am trying to create is in www/images/gallery.

I have tried many variations of setting the path such as ../images/gallery or home/www but nothing seesm to work

define("PATH", "/www/images/gallery");

$dir = 'a1234';

$targetfilename = PATH . '/' . $dir;

if (!is_file($dir) && !is_dir($dir)) {
    mkdir($dir); //create the directory
    chmod($targetfilename, 0777); //make it writable
}
like image 349
Keith Power Avatar asked Jun 03 '26 01:06

Keith Power


1 Answers

You mkdir command just uses $dir, which is just 'a1234' (in the current working directory). This will fail (and make the chmod fail too).

The solution: you probably want to prefix $dir with PATH...

like image 110
ChristopheD Avatar answered Jun 05 '26 18:06

ChristopheD



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!