Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Uploading User Permissions Problem - Safe Mode ON

Status
Not open for further replies.

MSRez

Programmer
Dec 22, 2004
57
EU
I'm having difficulty with the uploading of files to dynamically created directories, i.e. those that are created by PHP and are assigned an Apache user ID. The problem is that uploaded files cannot be copied to these directories when safe mode is set to on because the user IDs for directory and file are different and so it is disallowed.

The dynamic directory creation is pretty crucial and I need to keep it in place and yet allow uploading to them once more. Does anyone know a way around this without having to turn safe mode off?
 
Why would the userids for the directories and files be different? Aren't both being created by scripts running on the same web server?


Want the best answers? Ask the best questions! TANSTAAFL!
 
Yes, both are created on the same web server, even by the same script so you wouldn't expect it but I still get errors like this:

SAFE MODE Restriction in effect. The script whose uid is 502 is not allowed to access <dir> owned by uid 100 in <script> on line x
 
You could try the old "FTP to localhost" trick. Bascially, you have your script ftp_connect() to the local machine and copy the file over using ftp_put() or ftp_fput(). Since the copy is going through FTP, PHP's restrictions on filesystem access don't apply.

The down side of this is that you need to have FTP access to the web server and you have to store the account credentials someplace on the server where your script can read them. Not to mention it's cumbersome and inefficient. However, if you can't change the server configuration, your options are kind of limited.
 
I thought about using FTP functions to solve the problem but I'd rather not for exactly the reasons stated.

It's not that I can't turn safe mode off, it's just the server admin would prefer it on and since every thing else works with it on I'm really wanting to find a way around it.
 
Well, you could always change the file ownership on the server so that your scripts and the directories you're writing to all belong to the Apache user. That would put you incompliance with the safe mode restrictions and eliminate the problem. It's also impossible to manage without root access, but that's a different story.

Other than that, I'm out of ideas. There aren't that many ways around safe mode because, well, it would completely defeat the purpose of safe mode.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top