Closed Thread Icon

Topic awaiting preservation: php mkdir permissions (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=23389" title="Pages that link to Topic awaiting preservation: php mkdir permissions (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: php mkdir permissions <span class="small">(Page 1 of 1)</span>\

 
mobrul
Bipolar (III) Inmate

From:
Insane since: Aug 2000

posted posted 09-22-2004 15:19

I'm trying to write some php which will let me:
*upload a txt file
*do some stuff
*create a new directory and place a copy of the text file in that new directory.

I've tried putting together a simple test, and I'm running into errors with creating a new directory. I've been in contact with my host (<plug>Pugzly, at RunningWolf, provides great service, is reasonably priced, and one hell of a nice guy.</plug> and he says he doesn't think it's a server permissions problem.

I don't know much about what I'm doing here, so we both agreed it may be best to simply bring it here.

code:
Warning: chmod failed: Operation not permitted in
/pathToWebRoot/httpdocs/fileTest.php on line 21

Warning: MkDir failed (Permission denied) in
/pathToWebRoot/httpdocs/fileTest.php on line 22

Warning: Unable to create
'/pathToWebRoot/httpdocs/test/newDir': Permission denied
in /pathToWebRoot/httpdocs/fileTest.php on line 23

# CODE
-- ----
17 $file = $_FILES['fileTest']['tmp_name'];
18 $newDir = "/pathToWebRoot/httpdocs/test/newDir";
19 $test = "/pathToWebRoot/httpdocs/test";
20
21 chmod($test,0777);
22 mkdir($newDir,0600);
23 copy($file,$newDir);



Any help or insight would be much appreciated.

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 09-22-2004 15:47

I think it's possible it is a permissions problem of sorts.

I'm not sure how the server you're on runs PHP, but if it runs it as a different user from what it would when you log in on the command line or via ftp, that could be causing your problem. If PHP runs under it's own user, it would not let you chmod the $test directory because the php user doesn't own it. This would in turn cause the other functions after it to fail.

Try to chmod the /test directory in the same manner you created it and then try it again.

-Butcher-

(Edited by butcher on 09-22-2004 15:49)

mobrul
Bipolar (III) Inmate

From:
Insane since: Aug 2000

posted posted 09-22-2004 16:14

Of course, you are correct. I did as you said and all was mostly well.
I then had a new problem on line 23 when I tried to copy the file from the temp directory into a file named the same thing as the directory I just created. That was quickly fixed by making line 23 read:

code:
copy($file,$newDir."/index");


Now I have a new directory named "newDir" in the "test" directory. In that "newDir" I have a file named "index", which is identical to the text file I uploaded.
...just as I wanted.
Mr. Butcher, you're the man. Thanks.

(Edited by mobrul on 09-22-2004 16:16)

butcher
Paranoid (IV) Inmate

From: New Jersey, USA
Insane since: Oct 2000

posted posted 09-22-2004 16:21

I'm glad I was able to help you get it sorted out.

-Butcher-

« BackwardsOnwards »

Show Forum Drop Down Menu