iwato Posted March 21, 2010 Share Posted March 21, 2010 QUESTION: What could be causing the following error message? Once again the file that contains the PHP code is in the same folder in which $file should be copied.ERROR MESSAGE: "Warning: copy(nonPHP_file.txt) [function.copy]: failed to open stream: Permission denied in ..." <?php $filepath = "../fopen/nonPHP_file.txt"; $file = "nonPHP_file.txt"; copy($filepath,$file); ?> Roddy Link to comment Share on other sites More sharing options...
boen_robot Posted March 21, 2010 Share Posted March 21, 2010 PHP may be running as "nobody", and "nobody" may not have permission to access files. Contact your host for that. They should somehow let you run PHP as yourself, thereby giving PHP access to all of your files and folders. Link to comment Share on other sites More sharing options...
iwato Posted March 21, 2010 Author Share Posted March 21, 2010 PHP may be running as "nobody", and "nobody" may not have permission to access files. Contact your host for that. They should somehow let you run PHP as yourself, thereby giving PHP access to all of your files and folders.Thanks for responding, but this cannot be. These results are arising from a test server on my own machine. In the event that it could a source of trouble and a solution I am using MAMP Pro.Roddy Link to comment Share on other sites More sharing options...
boen_robot Posted March 21, 2010 Share Posted March 21, 2010 Oh. OK.Try to run <?php phpinfo() ?> and search for "USERNAME". What's in there? It should be your username. If it's "nobody", then MAMP Pro needs to somehow be tweaked (I'm not sure how though).If it's your username, try to first run <?php chmod("nonPHP_file.txt", 0777); ?> (from a file in the same folder of course) Link to comment Share on other sites More sharing options...
Synook Posted March 21, 2010 Share Posted March 21, 2010 chmodding the relevant files to 777 should always solve permissions issues. Note that even if you are running PHP on your "own" machine, permissions problems could still occur, as PHP may not run as the current user (i.e. "yourself"), or a fully privileged user. Link to comment Share on other sites More sharing options...
iwato Posted March 21, 2010 Author Share Posted March 21, 2010 Try to run <?php phpinfo() ?> and search for "USERNAME".I ran phpinfo(), but a keyword search did not reveal anything called USERNAME. What I did find among other things, however, is the following:PHP COREignore.user.abort : Offuser.dir : no valueMYSQL/MYSQLImysql.default.user : no valuemysquli.default.user : no valueSTANDARDuser_agent : no valueENVIRONMENTUSER : iwatoHOME : /Users/iwatoBy the way, MAMP Pro does give me access to a file called php.ini in which a search for the term USERNAME revealed the following:; The directory under which PHP opens the script using /~username used only; if nonempty.user_dir =Is the above helpful? Link to comment Share on other sites More sharing options...
boen_robot Posted March 21, 2010 Share Posted March 21, 2010 Yes. The "Environment" part (and the "USER" part of it to be more precise) shows PHP indeed runs as your username.Therefore, chmod(), as shown above should work. In fact, to prevent future problems, I'd suggest you also do: <?php chmod(getcwd(), 0777); ?> to enable yourself full access to the folder the PHP script is in and everything inside. Link to comment Share on other sites More sharing options...
iwato Posted March 21, 2010 Author Share Posted March 21, 2010 In fact, to prevent future problems, I'd suggest you also do:<?php chmod(getcwd(), 0777); ?> to enable yourself full access to the folder the PHP script is in and everything inside. QUESTION ONE: What is getcwd( )? I looked this function up in the function reference of the PHP website, and it did not appear.QUESTION TWO: Does setting my permissions to 0777 affect anything besides the PHP environment of my webserver?QUESTION THREE: In so far as online security is a problem would it not be wiser for me to reset my permissions as follows: 0774 or even 0770?Roddy Link to comment Share on other sites More sharing options...
boen_robot Posted March 21, 2010 Share Posted March 21, 2010 QUESTION ONE: What is getcwd( )? I looked this function up in the function reference of the PHP website, and it did not appear. Are you sure? QUESTION TWO: Does setting my permissions to 0777 affect anything besides the PHP environment of my webserver?Yes. Any program that runs with your username (i.e. any program you start on your computer) will also have full access to those files. QUESTION THREE: In so far as online security is a problem would it not be wiser for me to reset my permissions as follows: 0774 or even 0770?If there's no way any remote user could have direct access to your computer, there's pretty much nothing to worry about. If you want to have, say, and FTP server, or SSH server, it might be wise to deny yourself execution rights to those (and all non essential) files. Link to comment Share on other sites More sharing options...
iwato Posted March 22, 2010 Author Share Posted March 22, 2010 Are you sure?Thank you for the very thorough response to my many questions. I am a little embarrassed by the fact that I was unable to find the getcwd() function in the list, though. Certainly my lack of understanding about the alphabetization of the underscore played an important role in my oversight.This said, I do have one more very important question regarding the use of the getcwd() and chmod() functions. When setting the permissions for a particular file using the chmod(getcwd(),0###) are the permissions made the same for all of the folders along the path or only for the file containing the command at the path's end?Roddy Link to comment Share on other sites More sharing options...
boen_robot Posted March 22, 2010 Share Posted March 22, 2010 I'm not completely sure, but I believe permissions are inhereted by default, i.e. unless you say otherwise, all subfolders and files inside the folder get those permissions as well.That's the case on Windows at least. I don't know for sure how Linux (and inherently, MAC) behave. Link to comment Share on other sites More sharing options...
iwato Posted March 22, 2010 Author Share Posted March 22, 2010 Note that even if you are running PHP on your "own" machine, permissions problems could still occur, as PHP may not run as the current user (i.e. "yourself"), or a fully privileged user.I am still confused about how to proceed with the issue of permissions and am attaching an image of my current MAMP PRO permission settings. The confusion arises because of the following lack of conformity between my MacOS and MAMP Pro:When I check folder permissions using the GetInfo command of my MacOS, group permissions are not an issue, rather the emphasis is on the user, the administrator, and others. When I check permissions using MAMP Pro, however, there is no mention of the administrator, and the emphasis is on the user, the group, and others ( see image ).Could someone help me sort out this apparent contradiction?Roddy Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.