Jump to content

Read/Write to apache passworded files


PC Nerd

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

 

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

:P - 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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.