Page 2 of 4

Posted: Sat May 22, 2004 7:10 am
by mjseaden
Hi Mark

It's now telling me that glob() is an undefined function :evil:

Posted: Sat May 22, 2004 7:18 am
by markl999
Ack, your PHP version is too old.
Try this one instead then.

Code: Select all

<?php
function foo($dir){
    if ($handle = opendir($dir)) { //no trailing / on $dir
    while (false !== ($file = readdir($handle))) {
        if (!is_dir($dir.'/'.$file)) {
            echo 'Deleting '.$dir.'/'.$file.'<br />';
            unlink($dir.'/'.$file);
       }
    }
    closedir($handle);
    }
}
?>
It will only delete files (if it can), you can deal with directories later if it works.

Posted: Sat May 22, 2004 7:23 am
by mjseaden
Mark

The script seems to run okay but it doesn't seem to do anything - the files are still there. Arrghhh!

Posted: Sat May 22, 2004 7:24 am
by mjseaden
Additionally, Launchcode earlier said to telnet the server and use 'man chown...' to change the ownership settings. My MS Telnet reports it doesn't recognise the command 'man'. Arrgghhh!

Posted: Sat May 22, 2004 7:27 am
by markl999
Not sure why Launchcode told you that. You can't chown a file that's owned by someone else :o

Posted: Sat May 22, 2004 7:27 am
by mjseaden
Mark, I changed the directory from uploads to some directories internal to uploads that contain files (uploads itself contains no files just directories). I'm getting the following error:

Code: Select all

Deleting /XXX/upload/50cd23f1ec7bed66799da314534f8992/31580218240ad07e79df41big.jpg
Warning: Unlink failed (Permission denied) in /XXX/delete_uploads.php on line 9

Posted: Sat May 22, 2004 7:28 am
by markl999
And XXX is the full path to the upload directory?

Posted: Sat May 22, 2004 7:29 am
by mjseaden
Yes it is - I've put XXX instead of the full transcript, but it's correct as the script seems to be finding the files in that directory.

Posted: Sat May 22, 2004 7:37 am
by mjseaden
Is there any way I can change the ownership of all the files and directories in uploads to my root username? Why has move_uploaded_files written the files to my upload directory under ownership of 'apache' group 'apache' instead of my own root username? Is there any way I can configure the server only to write under my ownership (e.g. using .htaccess?).

Many thanks

Mark

Posted: Sat May 22, 2004 8:41 am
by mjseaden
/bump

Posted: Sat May 22, 2004 9:06 am
by launchcode
If you can't issue a man command - you probably don't host on a Unix server (either that or they are *very tight*) on their security!
Not sure why Launchcode told you that. You can't chown a file that's owned by someone else
Want to bet on that? ;) I agree you need super-user privs (or an access level equivalent to that), but with so many virtual hosting packages that give you this these days - it's not unreasonable to try it.

mjseaden - can you run a directory listing (ls -l) off and print the results here? It should show us something similar to this:

Code: Select all

-rw-r--r--   1 fatal2  users   3754 Nov  1  2001 usenet.php
-rw-r--r--   1 fatal2  users   8254 Jul  4  2003 view.php
-rw-r--r--   1 fatal2  users    744 Nov  1  2001 xt_addgame.php
-rw-r--r--   1 fatal2  users    757 Nov  1  2001 xt_addhuman.php
Then at least we can see what privs have been set.

Posted: Sat May 22, 2004 10:00 am
by mjseaden
Actually, probably more relevant:

Code: Select all

drwx---r-x   2 apache   apache       8192 May 20 23:02 50cd23f1ec7bed66799da314534f8992
drwx---r-x   2 apache   apache       4096 May 21 19:09 a2acfa8de77a079c1ff9e54b2b25aede
drwx---r-x   2 apache   apache       4096 May 21 19:30 e01286f5adfc6454fdbcca2e891de258
drwx---r-x   2 apache   apache       4096 May 20 23:17 eb50a4595bf0e4ce2243a41653f56f05
drwx---r-x   2 apache   apache       4096 May 21 19:11 ecf43f986b3367df1246172cf8df1690
drwx---r-x   2 apache   apache       4096 May 21 19:16 fcb82ceebeb2f5c4fc262b1e8f713997
These are directories in uploads. Inside these directories are files. I am not able to delete, via any method I have so far tried, either these directories or the files contained within them.

Many thanks

Mark

Posted: Sat May 22, 2004 10:03 am
by mjseaden
In other words, these files/directories are stored under ownership of username 'apache' and group 'apache', not under my root username 'root' and group 'root'.

..?

Posted: Sat May 22, 2004 10:33 am
by mjseaden
Hi, just to summarize the problem:

(1) I am uploading files to a directory on my server called 'upload', using a web interface using the usual POST data -> move_uploaded_file method via PHP.
(2) PHP, however, is uploading these files under the username 'apache' and group 'apache'. This is not the username or group I use to login to my server via FTP (or anything else) for my shared hosting space.
(3) This means that, since I am logging in as a username not equal to 'apache', I cannot use CHOWN via telnet to change the ownership of these files to my username and group, so that I can delete them myself. I therefore have files on my server that I cannot delete.

Additionally:

(4) When trying to run a PHP script using 'unlink' to delete them, it strangely still gives me permission errors. This is the part I particularly don't understand.

Can anyone help?

Many thanks

Mark

Posted: Sat May 22, 2004 10:37 am
by launchcode
What are the directory permissions for "uploads" (and anything else higher-up than this that might effect it) ?