Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3989788
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:24:59+00:00 2026-05-20T06:24:59+00:00

I use this custom, simple script I made, somehow it’s failing but it always

  • 0

I use this custom, simple script I made, somehow it’s failing but it always returns true.

This class unlink the files that are placed in an array which goes through them then increments the counter on success of a file that was deleted, this is my script:

<?php

class Delete 
{
    function deleteFiles($array)
    {
        if(is_array($array))
        {
            $filecount = count($array);
            $count = 0;

            foreach($array as $file)
            {
                if(file_exists($file))
                {
                    $remove = unlink($file);

                    if($remove)
                    {
                        $count++;   
                    }
                }
                else
                {
                    return false;
                }
            }

            if($count == $filecount)
            {
                return true;    
            }
            else
            {
                return false;   
            }
        }
        else
        {
            return false;   
        }
    }
}

?>

Basically I need improvements on how to make it foolproof so that the images in the array are completely deleted not returning true once an unlink has deleted the file when it hasn’t, so I have no idea why it’s not actually deleting the files properly.

Sometimes it works perfectly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T06:25:00+00:00Added an answer on May 20, 2026 at 6:25 am

    change if($remove) to if($remove && !file_exists($file))

    Also, be aware that sometimes an unlink will fail on Windows: http://ie.php.net/manual/en/function.unlink.php#100580

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've coded a little simple script that allows me to use custom checkboxes. It
At the moment, whenever I need a custom dialog, however simple, I use Delphi's
I put together a simple script that pulls the product name, category name and
I'm trying to use this tooltip plugin: http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/ . I can't seem to get
I am attempting to build a simple WPF Application using msbuild via a custom
I have built a variety of little scripts using Ruby's very simple Queue class,
I need help loading a custom file format into my program made in c++...
I use a simple Google Maps API on a simple webpage. The map contains
I've got this piece of script, and I'm trying to hide two divs (#black
Doubt this is possible as I don't have a 1 page app, but pretty

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.