It's now telling me that glob() is an undefined function
Not able to delete files from my own server!
Moderator: General Moderators
Ack, your PHP version is too old.
Try this one instead then.
It will only delete files (if it can), you can deal with directories later if it works.
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);
}
}
?>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 9Is 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
Many thanks
Mark
- launchcode
- Forum Contributor
- Posts: 401
- Joined: Tue May 11, 2004 7:32 pm
- Location: UK
- Contact:
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!
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:
Then at least we can see what privs have been set.
Want to bet on that?Not sure why Launchcode told you that. You can't chown a file that's owned by someone else
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.phpActually, probably more relevant:
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
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 fcb82ceebeb2f5c4fc262b1e8f713997Many thanks
Mark
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
(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
- launchcode
- Forum Contributor
- Posts: 401
- Joined: Tue May 11, 2004 7:32 pm
- Location: UK
- Contact: