I am using Drupal(php based open source software) to build a website. Right now I am experiencing a weird problem. When I use fopen in a test.php and run from command line: "php test.php", I can open file and read/write/append, but if I include that portion of code in side the drupal module I wrote, I get permission denied error. Can anyone help me on this? Many thanks
I re-evalued my problem, i don't think it has anything to do with drupal any more the problem now is that I can read a file but not write and append. here is the permission of the file I want to open: -rwxrwxrwx 1 root root .... pass.txt
here is the code: $file = "/web/website/test.txt"; $fh = fopen($file, "r"); $data = fgets($fh); print $data. now the problem is if I put the text file under /tmp, I can read and append, but if I move to another directory, I can't read, write, append. all throw me permission denied error. I checked the directory permission, it's 777, and the user and usergroup are apache apache.
The problem is you do not use the / from the beginning alone. That indicates that you are using the absolute root. Which is outside of the web folder. Of course it is going to throw an error... use ./ instead of / at the start.
I tried changing / to ./, I got this error warning: fopen(./web/files/test.txt) [function.fopen]: failed to open stream: No such file or directory
I changed the file name from test.txt to test, now I can read the file, but still can't write or append to the file.
Ok seems like you are defining the directory wrong. If the file is 1 level deeper use ../ if it's 2 levels ../../
It's your file structure. You need the full path to your server home directory. For example on my hosting (MediaTemple) I would have to address the file in this way to open it for my domain ProbablySucks.com /domains/probablysucks.com/html/test.txt I suggest FTP'ing to your directory with FileZilla and copying the server path from the top it shows you.
jj0914, did you solve your problem? I have the same problem here: fopen("/opt/www-data/test.log", "a"); gives Permission Denied. I checked the permissions on the filesystem, apache is the owner (if not, still everybody has write permission). The path is correct. getmyui() and getmygid() give 48 and 48. stat('/opt/www-data/test.log')['uid'|'gid'] same values. I tried using /tmp instead, works. I cannot see why I can't write to /opt. Also tried using system("touch /opt/www-data/test") which gives the same issue. On the console with sudo -u apache touch /opt/www-data/test it works. Any idea? (As always: works on another system but can't see the difference.) Thanks, Tim