Reputation: 14141
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
}
Upvotes: 2
Views: 1031
Reputation: 7517
It makes the $dir
in your current working directory, however, it doesn't mean that this equals your $targetfilename
. I would say that you have to do mkdir($targetfilename)
rather than mkdir($dir)
.
Upvotes: 2
Reputation: 4896
The problem is that you cannot chmod a file that you haven't made. For that reason, I've changed the line
$task = chmod($targetfilename, 0777); //make it writable
to
$task = chmod($dir, 0755); //make folder writable
Tip: If you want a folder to be writable, chmod it to 755 and not 777. 777 is for files.
Upvotes: 2
Reputation: 193
Dear chmod() create some time problem. So i will suggest u that use this mkdir("/path/to/my/dir", 0700); if u want the created directory should be ready and wirtable then use this mkdir("/path/to/my/dir", 0777);
Upvotes: 2
Reputation: 116117
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...
Upvotes: 3