2

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
}
4
  • 1
    Does PHP have write access to /www/images/gallery? Commented Apr 28, 2012 at 18:52
  • 1
    mkdir( $dir ) is likely returning false. Might want to check the return value of it before attempting to chmod a file within. Commented Apr 28, 2012 at 18:55
  • 777 gives ALL permissions to ANY user. Figure out what exact permissions you need to grant, don't just put 777 on stuff: you're exposing full permissions for hackers to do things with your system. Commented Apr 28, 2012 at 19:02
  • yes I just set them for testing and then lock down everything for release Commented Apr 28, 2012 at 19:03

4 Answers 4

3

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...

Sign up to request clarification or add additional context in comments.

1 Comment

yes I think this is the problem, what would you think the correct path would be?
2

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);

Comments

2

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.

Comments

2

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.