Forum Moderators: coopster

Message Too Old, No Replies

Can't delete pictures from server after I upload with PHP script

         

hannamyluv

3:26 am on Nov 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I am relativly new to PHP, so for all I know this is normal... anyhoo

I am using a php script to allow people to upload images, but if I go onto the server later, I am unable to delete or rename the images. Am I doing something wrong that is causing this? Am I missing something here?

eelixduppy

3:39 am on Nov 28, 2006 (gmt 0)



You should be able to do whatever you want with the files. Check the permissions to see if you have the access.

Doesn't make too much sense. Are you getting any error messages?

bleak26

7:19 am on Nov 28, 2006 (gmt 0)

10+ Year Member



somthing like This happens on some of the shared hosting i use.for me its got somthing to do with the permsions or account php uses to write the files. it only happens to a few of my user uploaded files and the administrator can delete them for me if i ask. instead i found it was easier and better than bothering him to write php script which deletes the files i wanted gone and because php put them there , php can remove them.

swa66

9:45 am on Nov 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Assuming a unix server ...

Typically the webserver will run as a user with little privileges (e.g. wwwserver). And it will typically not run as the user account of interactive users.

So if the webserver creates files, they become owned by the user running the website (wwwserver).
If that is done in a directory also owned by that same user and not giving rights to a specific group the interactive user is a member of (or the world), then the interactive user will not have the rights to manipulate the files.

You need to check the setup of your server:

  • if you can become root, root can access all files and change ownership of files. [Very unlikely in shared hosting setups and if it is, run! (other users can do anything to you)]
  • is there a group that both you and the webserver are a member of? If so: modify your scripts to change the group on any file or directory it creates to that group and give the right for group to write the directory/file)
    WARNING: this means any script running on the webserver (even from other users) can access your files and even modify the contents.
  • as a last resort: set the world write bits on any file or directory your scripts create.
    WARNING: this means any file like this is vulnerable toward reading and modification by any other script or user running on the server.

    php:
    chmod(): [php.net...]
    chgrp(): [php.net...]

    Take care with race conditions on shared servers.

  • jatar_k

    4:48 pm on Nov 28, 2006 (gmt 0)

    WebmasterWorld Administrator 10+ Year Member



    the trick is to use a script to delete them as well
    [php.net...]