Jump to content
xisto Community
Sign in to follow this  
electriic ink

Delete Files And Directories Using Php following up from creating and writing

Recommended Posts

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:

 

<?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:

 

<?rmdir("/home/bla/public_html/");?>

All in all a very simple tutorial explaining this, any questions?

Share this post


Link to post
Share on other sites

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

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

Hope this helps.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
edit and delete imageDelete Files And Directories Using Php

I want to upload image to server.

then I want to diplay  this image.

then I want to Edit this image.

Best Regard

Hameed ul.Haq

Share this post


Link to post
Share on other sites

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

<br />chmod("/adirectory/", 0777); //Will CHMOD a directory<br />chmod("/adirectory/afile.txt",0777); //Will CHMOD a file<br />
<br /><br />Hope this helps.<br />
<br /><br /><br />
Yes This tip was really helpfull and the whole process is quite easy to do and works like a charm and is a great technique.............................

But although the method is quite long can any1 suggest a smaller method that would really help us to execute in less time.....

Share this post


Link to post
Share on other sites
re feedbackerDelete Files And Directories Using Php

1) CHMOD is a tool used to change the permisions of a file a directory, it uses numeric values for the permisions with the higher number being more access. It also breaks the number into single digit parts, each of which applies to different groups, one is everyone, one is owner, I'm not sure what the other(s) are.

 2) I thought to connect toa database u needed something like:$string="server:port, user, password";

Then to connect to the indivuidual database, you needed something likeMysql_select_db("dbname, "$string);

Share this post


Link to post
Share on other sites

I'm trying with unlink()$myFile = "../photos/".$filename;  << doesnt exist on your serverUnlink($myFile);But nothing happens...  Any idea? Thanks!

 just this suggestion old but useful I suppose

$myFile = "path/to/folder/with/photos/".$filename; Unlink($myFile);

you don't want a relative path "../photos"or a web link http://forums.xisto.com/no_longer_exists/ your telling the server to do something explicit, so be explicit

while your at this you might just want to make this nice and secure. Wouldnt want just any old file to be deleted eh

-reply by chris

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.