Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Delete Files And Directories Using Php, following up from creating and writing
electriic ink
post Sep 15 2005, 05:09 PM
Post #1


Incest is a game the whole family can play.
Group Icon

Group: [MODERATOR]
Posts: 1,205
Joined: 11-February 05
From: Heaven
Member No.: 3,709



How To Delete Files and Directories
follow up from creating them

Hello all and welcome to my second tutorial involving file management. In my previous tutorial, I explained how to create, write and read files. In this tutorial I'll explain how to remove the files and directories you took so long to create. I did not explain last time how to create directories as I did not know, now I do, you can use the mkdir() function.

Now with this tutorial....

Removing Files

Removing files can easily be done with the unlink() function:

CODE
<?

unlink("stuffStorge.txt");

?>


The file which you wish to remove must have 0777 chmod permissions aswell as the directory that the file is stored in.

Removing Directories

I have never tried doing this myself but it can be done with the rmdir() function, but I presume like unlink() both the directory you are trying delete and the one that the directory is stored in must have 0777 permissions:

CODE
<?

rmdir("/home/bla/public_html/");

?>


All in all a very simple tutorial explaining this, any questions?
Go to the top of the page
 
+Quote Post
mguanumen
post Sep 15 2005, 05:48 PM
Post #2


Newbie [Level 1]
*

Group: Members
Posts: 12
Joined: 12-September 05
Member No.: 11,794



!! The file which you wish to remove must have 0777 chmod permissions !!

the question is how change the permissions with PHP? is possible?
Go to the top of the page
 
+Quote Post
rvalkass
post Sep 15 2005, 06:42 PM
Post #3


apt-get moo
Group Icon

Group: [MODERATOR]
Posts: 2,055
Joined: 28-May 05
From: Hertfordshire, England
Member No.: 7,593
Spam Patrol



Yes, use this code to change CHMOD values. You must use octal numbers (e.g. always have 4 digits starting with 0).
CODE

chmod("/adirectory/", 0777); //Will CHMOD a directory
chmod("/adirectory/afile.txt",0777); //Will CHMOD a file


Hope this helps.
Go to the top of the page
 
+Quote Post
TripleH13
post Sep 17 2005, 04:18 AM
Post #4


Privileged Member
*********

Group: Members
Posts: 623
Joined: 26-August 05
Member No.: 11,160



thanks for this i havent really had any problems deleting files yet but i havent really done anything big like that but i think i am going to delete some stuff so i hope this tutorial will come in use to me when i am doing the file deleting
Go to the top of the page
 
+Quote Post
mendezgarcia
post Oct 5 2005, 12:10 AM
Post #5


Newbie [Level 3]
***

Group: Members
Posts: 46
Joined: 11-September 05
Member No.: 11,743



The biggest problem with chmod() is that most of the servers will restrict PHP from using it.

I don't know about Trap17 though
Go to the top of the page
 
+Quote Post
iGuest
post Jan 11 2008, 05:09 AM
Post #6


Trap Double Mocha Member
***************

Group: Members
Posts: 2,360
Joined: 21-September 07
Member No.: 50,369



2 Questions CHMOD || MySql
Delete Files And Directories Using Php

1) what is CHMOD ? What does it do ?

2) I'm currently making a website that people can make they're selves members on but when I try and interact with mySql db it says "Undefined function mySwl_Connect()" Whats that about ? ive tryied everything;

[Example]
$String = "MydataBase.Sql";
$con = mysql_connect($String);
[/Example]

But I always get the same error. I've checked my php.Ini file but everything *seems* oright. Any ideas ?

Any help appreciated, Thanks, Mark.

-Huzi
Go to the top of the page
 
+Quote Post
iGuest
post Jan 17 2008, 12:05 AM
Post #7


Trap Double Mocha Member
***************

Group: Members
Posts: 2,360
Joined: 21-September 07
Member No.: 50,369



Deleting a directory and its content
Delete Files And Directories Using Php

I'm trying to use rmdir() to delete a directory, but I'm getting "Directory not empty" error. How can I remove the directory and its content?

-Sharif
Go to the top of the page
 
+Quote Post
iGuest
post Mar 26 2008, 05:25 PM
Post #8


Trap Double Mocha Member
***************

Group: Members
Posts: 2,360
Joined: 21-September 07
Member No.: 50,369



How do I delete a file wich is located in a different directory
Delete Files And Directories Using Php

I have all my php files in a directory called templates, and I need to remove (delete) files (jpg) in a directory called photos. My Directory list looks like this:

Root/
/photos/
image1.Jpg
image2.Jpg
/templates/
removingfiles.Php

I'm trying with unlink()
$myFile = "../photos/".$filename;
Unlink($myFile);

But nothing happens...

Any idea?

Thanks!



-question by Mr Serra
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. A Guide To Css And Creating A Stylesheet(15)
  2. Creating Your Own Icon(23)
  3. Css And Javascript Combined For Dynamic Layout(9)
  4. How To Read And Write Files Using Php(20)
  5. How To Clear Your Temp Files(17)
  6. Building An Unordered List Of Anchors(4)
  7. Creating A Simple Image Viewer(3)
  8. Templating System Using Php Includes(13)
  9. Creating A Timer Program(8)
  10. Php Script To Make A Link List(6)
  11. How To Open Bam & Tt Files, long 3 part tutorial(2)
  12. How To Create Self-unzipping Files(18)
  13. How To Chmod Files(16)
  14. Tutorial: Creating Custom Icons For Devices(0)
  15. Flatfile User Login/signup(24)
  1. How To Fix Problems With Shareaza(1)
  2. Cpanel Analysis And Log Files(0)
  3. Programming In Glut (lesson 1)(0)
  4. Programming In Glut (lesson 4)(0)
  5. How To Delete Your Search History In Microsoft Internet Explorer(3)
  6. How To Better Compress Files In Winrar(7)
  7. Creating A Resume(1)
  8. Creating Navigation For Html Websites(12)
  9. Writing An Essay - Part I: Sentences(6)
  10. How To Hide Your Important Files And Folders(7)
  11. Download Files Off Esnips.com(0)
  12. Getting Started With Mysql(2)
  13. Debug Exe Files(4)