PHP delete file in directory

If to delete a single file, use the unlink() function. Unlink can safely remove a single file.
That function will delete what you pass it as a parameter.
For example, delete single file

$path= $dir.'/'.$file;

if (is_file($path))
{
    unlink($path);
}

Delete multiple file in a directory, use loop:

foreach($FilesArray as $file)
{
	if (is_file($file))
	{
	    unlink($file);
	}
}

By Keenlio, September 15, 2014

8 Comments

  1. You are incredible! says:

    I was suggested this web site by my cousin. I am not sure whether this post is written by him as nobody else know such detailed about my difficulty. You are incredible! Thanks!

  2. This is very interesting says:

    This is very interesting, You are a very skilled blogger. I’ve joined your feed and look forward to seeking more of your wonderful post. Also, I’ve shared your web site in my social networks!

  3. pn vi says:

    Thanks for another excellent article. Where else could anyone get that type of information in such a perfect way of writing? I’ve a presentation next week, and I am on the look for such info.

  4. web sx says:

    I think other web-site proprietors should take this web site as an model, very clean and great user friendly style and design, as well as the content. You’re an expert in this topic!

  5. Heike says:

    Hi all, here every one is sharing such experience, thus it’s nice to read
    this website, and I used to go to see this web site everyday.

  6. web sx says:

    I think other web-site proprietors should take this web site as an model, very clean and great user friendly style and design, as well as the content. You’re an expert in this topic!

  7. Felicia says:

    Thanks for a marvelous posting! I certainly enjoyed reading it,
    you could be a great author. I will make certain to bookmark your blog
    and will come back sometime soon. I want to encourage you
    continue your great writing, have a nice evening!

  8. Gertrude says:

    I will immediately grasp your rss as I can’t in finding your email subscription link
    or e-newsletter service. Do you’ve any? Kindly let me understand so that I may
    just subscribe. Thanks.

    my homepage Clash Of Clans Hack android

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *


three × 9 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>