>Our image gallery application takes a directory tree of images uploaded
>by the user and then does all sorts of magic to make thumbnails, track
>comments, and so on.  The only thing owned by the user is the directory
>tree and its contents; everything else is owned by the web server ID.
>All of this works well until a user wants to change the name of a subtree
>in the source directory; all of the 'nails are "lost" (since they're now
>unrelated to the source tree, and they just hang around taking up space),
>and even worse all of the comments are lost.
>The problem, of course, is that the user can't rename the cache directory
>and the web server can't rename the source directory.

Put the web server user and the real user into a common "group" and make all
the files/directories be "group" writable is one possible answer.

Another would be to write a shell script for the "real" user (or web) that
will move/rename the files around and make it world-executable.  Make sure
you only allow it to 'work' in the directories you want, or a malicious user
could re-arrange your whole site for you.

You could also "cheat" and create an extra "level" in your directory
structure where the new directory is owned by the web user:


If the webuser owns 'webuser' it can do whatever it wants to the things
inside that it also owns.

If you have problems getting a directory owned by 'webuser' to exist in the
first place, you can:

Write a script in PHP that does:
<?php mkdir("/full/path/to/realuser/webuser") or die("Didn't work yet.");?>

Then, "chmod 777 realuser", surf to the page above so the webuser can create
its directory, and "chmod 755 realuser" again.

You'll be "vulnerable" for that brief moment while you're doing this, but
that's life.

>Has anyone already solved this problem -- preferably without reeking too
>terribly of a kludge?  We've already thought of a script that the user
>calls which renames the cache side and then says "OK, so *now* go and
>rename the source side with ftp like you would anyway" but that's not
>pretty by any stretch.  I just can't get past the concept that we're
>mixing user ID and web server ID and that you just can't.
>Of course, if the same old question ("How do I have the web server do
>things in a user way?") has finally been answered, please let me know ;-)

There are some choices.

1. Use PHP-CGI and safe mode.
2. Use PHP-CGI and suExec (not *both* 1 & 2)
3. Use Apache 2.x (not quite recommended... yet.)

With 1&2 you'd take a performance hit on those pages that used CGI, but you
*CAN* run both CGI and Module at once, with different mime-types
(application/x-httpd-php and application/cgi-php) and extensions (.php and
.phpcgi)  Or you could even use .htaccess to ForceType the CGI scripts to
application/cgi-php even though they end in .php (or .htm or whatever you

Like Music?  http://l-i-e.com/artists.htm

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to