PC Nerd Posted December 30, 2008 Share Posted December 30, 2008 Hi, I've got a directory that is protected by apache .htaccess file. At the moment, it allows access to the one php file in the directory - however whenever I try and read or write to any of the other files - I get a permission denied error. Is there any way that I can open these files through php? Thanks Quote Link to comment Share on other sites More sharing options...
btherl Posted December 30, 2008 Share Posted December 30, 2008 Are you trying to read from and write to these files from php and getting permission denied? Are they files you created through some kind of admin interface or uploaded through ftp? If so the files may be owned by a different user to the one that your script runs as. That's my best guess given limited information. Don't worry about the .htaccess if this is the issue - .htaccess doesn't control these things. If you can show your code (or the relevant parts) that might help. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted December 30, 2008 Author Share Posted December 30, 2008 function setcurrentlockdata($data) { // Writes data about the current lock to the file. Can only be read using loadcurrentlock($data); $f = fopen("curlock", "w"); if($f == FALSE) { return 2; } if(flock($f, LOCK_EX)) { $r = @fwrite($f, $data); flock($f, LOCK_UN); } else { return 3; } fclose($f); if($r == FALSE) { return 4; } return TRUE; } Warning: fopen(curlock) [function.fopen]: failed to open stream: Permission denied in <FILE> on line 109 line 109 is @fopen(.....); Im not 100% sure about the permission's on a linux machine, how would I change the user of the files? Thanks Quote Link to comment Share on other sites More sharing options...
btherl Posted December 30, 2008 Share Posted December 30, 2008 Do you have shell access on this machine? If so you can use the "chmod" command to change permissions. Can you give a bit more detail about the setup? Is it hosted or on your own machine? Another option could be to use another writeable folder to create your lock file instead. /tmp is a good bet. That's not very secure though (if other people could also be writing to /tmp) Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted December 30, 2008 Author Share Posted December 30, 2008 Hi, shell access - so ill look into that ( im new to linux command line)..... /tmp is a good idea but I did want it all in a single directory so its easily "contained" etc. Thanks for your help. Quote Link to comment Share on other sites More sharing options...
btherl Posted December 30, 2008 Share Posted December 30, 2008 Well "shell access" is a term for hosting usually. It means you can use the command line. If it's your own machine then of course you can use the command line Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted December 30, 2008 Author Share Posted December 30, 2008 - either way I should be able to chmod... it jsut occured to me that it might be a case where the files arent "777", ie - readonly (because its reading from other files that were uploaded in the same session), so only the writing function to that file fails.... thus --- I think that its just a 777 issue ( Ill check). Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.