Deleting files in PHP
Moderator: General Moderators
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Deleting files in PHP
[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.
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.
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
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.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.
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
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
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
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
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");
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.
if you are in
and want to create
but no folder named test exists
youll have to do
in that order (using relative paths)
Code: Select all
/home/test/public_html/Code: Select all
/home/test/public_html/test/123/youll have to do
Code: Select all
mkdir('test');
mkdir('test/123');