Deleting files in PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Deleting files in PHP

Post 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.
User avatar
Nathaniel
Forum Contributor
Posts: 396
Joined: Wed Aug 31, 2005 5:58 pm
Location: Arkansas, USA

Post by Nathaniel »

User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post 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! :)
User avatar
Nathaniel
Forum Contributor
Posts: 396
Joined: Wed Aug 31, 2005 5:58 pm
Location: Arkansas, USA

Post 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.
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post 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
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

I believe the term you are looking for BDKR is marker, or flag - not pointer :p

[/huff]
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

Jenk wrote:I believe the term you are looking for BDKR is marker, or flag - not pointer :p

[/huff]
LOL. Thanx
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post 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 :(
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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");
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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)
Post Reply