Page 1 of 1

Deleting files in PHP

Posted: Tue Nov 15, 2005 3:46 pm
by jayshields
[Moderator note]: Moved to the PHP Code Forum

Ok, not sure if this was the right forum to post in, but here goes...

I'm developing a file upload/management system (as stated in a previous post), and I've got it to upload files, list files nicely, etc. Now I wanna delete files, the only way I can find in the PHP manual is ftp_delete(), but this requires FTP login details and FTP server info. I'm sure I've used a script in the past which allows the deletion of files and I cannot remember giving it my FTP login details.

I've seen rmdir(), which can remove directories without FTP details, but only empty directories.

I can't find any other functions to do this, so am I not looking hard enough or is this the only way?

Thanks guys.

Posted: Tue Nov 15, 2005 3:48 pm
by Nathaniel

Posted: Tue Nov 15, 2005 3:50 pm
by jayshields
Aha! Knew there had to be something, why's got a stupid name though?

Thanks dude.

Ps. Check my sweet quote in my signiture :)
Pps. Wow! 2 minute reply, awesome! :)

Posted: Tue Nov 15, 2005 3:57 pm
by Nathaniel
You can blame the stupid name on the authors of C, as the PHP function has the same name as the "delete file" function in C. :)

AND

100 posts.

Posted: Wed Nov 16, 2005 10:06 am
by BDKR
Nathaniel wrote:You can blame the stupid name on the authors of C, as the PHP function has the same name as the "delete file" function in C. :)

AND

100 posts.
Actually you can blame it on the fact that unlinking is a more correct term then deleting. What's really being done at the level of the OS and storage medium is a pointer (so to speak. Don't get in a huff!) to the space containing the file on the drive is being removed. In other words, it's still there on your drive but no longer acknowledge as being so. As far as the OS is concerned, it's now free space.

This is why the Police, FBI, CIA, and data recovery companies can often get deleted data off drives. This is also why tools such as srm (secure removal) exist.

Cheers,
BDKR

Posted: Wed Nov 16, 2005 10:33 am
by Jenk
I believe the term you are looking for BDKR is marker, or flag - not pointer :p

[/huff]

Posted: Wed Nov 16, 2005 10:36 am
by BDKR
Jenk wrote:I believe the term you are looking for BDKR is marker, or flag - not pointer :p

[/huff]
LOL. Thanx

Posted: Wed Nov 16, 2005 10:45 am
by jayshields
Ok, I'm just gunna revive this thread as this is a simple and slightly related question...

I'm trying to make new directories now, with mkdir(), I used $currentdir . $newdirname, because I thought that f.e. if the script was in whatever dir and you used mkdir("/newdir") it would put it in the same dir as the script, logically, but I get a permission denied error.

So, I'm led to presume I will need some sort of absolute URL, most probably not right from the domain, so f.e. If my script is in http://www.domain.com/script/ and i want to create the dir http://www.domain.com/script/newdir, what string would i pass to mkdir()? I'm led to think that it isn't "/newdir" and the PHP manual doesn't elaborate, it says "path/to/my/dir".

Thanks for any help and sorry if this is on the forum already, I forgot to search and now I've typed all this :(

Posted: Wed Nov 16, 2005 11:06 am
by s.dot
you'll need an absolute URL like mkdir("/home/blah/blah/newdir");

I've never tried making a new directory using a relative path, but if you want to try it, try leaving off the / and puting mkdir("newdir");

Posted: Wed Nov 16, 2005 12:32 pm
by josh
if you are in

Code: Select all

/home/test/public_html/
and want to create

Code: Select all

/home/test/public_html/test/123/
but no folder named test exists

youll have to do

Code: Select all

mkdir('test');
mkdir('test/123');
in that order (using relative paths)