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 9152095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:57:36+00:00 2026-06-17T11:57:36+00:00

function remove_directory($directory) { if (is_dir($directory) === true) { $contents = scandir($directory); unset($contents[0], $contents[1]); foreach($contents

  • 0
    function remove_directory($directory) {
        if (is_dir($directory) === true) {
            $contents = scandir($directory);
            unset($contents[0], $contents[1]);

            foreach($contents as $object) {
                $current_object = $directory.'/'.$object;
                if (filetype($current_object) === 'dir') {
                    remove_directory($current_object);
                    } else {
                    unlink($current_object);    
                    }
                }
                rmdir($directory);
            }
        }

    function delete_row($filecode) {
        $filecode = mysql_real_escape_string($filecode);

        mysql_query("DELETE FROM `files` WHERE `code` = '$filecode'");

        }
          $query = mysql_query("SELECT `id`, `username`, `title`, LEFT(`description`, 90) as `description`, `code`, `type`, `size`, `date` FROM `files` WHERE `username` = '$userfile' ORDER BY id DESC LIMIT $start, $per_page");

        while ($query_row = mysql_fetch_assoc($query)) {
            $fileuser = $query_row['username'];
            $filetitle = $query_row['title'];
            $filecode = $query_row['code'];
            $filedesc = $query_row['description'];
            $filesize = $query_row['size'];
            $filedate = $query_row['date'];
            $filetype = $query_row['type'];

            if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['dir'])) {
            $dir = basename($_POST['dir']);
            if ($dir[0] != '.') 
            remove_directory("files/$dir"); //these function work good and delete only one folder when I click Delete button
            delete_row($filecode); //these function delete me all row in database in first page when I click in second page delete button too what the .... I am so angry i cant believe what is happend it's gone my database  

        }

        if (empty($filedesc) === false) {   
        echo '<div id="linkstyle"><strong><a href="http://localhost/edu/1111111111111/userdownload.php?code='. $filecode . ' ">' , $filetitle , '</a></strong></div> <div id="displayfiledesc">' , $filedesc , '...</div><div id="displayfiledate"> &#149; ' , formatBytes($filesize) , ' &#149; ' , $filedate , ' &#149; ' , $filetype , '</div>';?>

        <form action="" method="post">
            <input type="hidden" name="dir" value="<?= $filecode?>">
            <input type="submit" name="delete" id="bdelete" value="Delete"><br><br>
        </form>

        <?php
        } else { 
        echo '<div id="linkstyle"> <strong><a href="http://localhost/edu/1111111111111/userdownload.php?code='. $filecode . ' ">' , $filetitle , '</a></strong></div> <div id="displayfiledate"> &#149; ' , formatBytes($filesize) , ' &#149; ' , $filedate , ' &#149; ' , $filetype , '</div>';?>

        <form action="" method="post">
            <input type="hidden" name="dir" value="<?= $filecode?>">
            <input type="submit" name="delete" id="bdelete" value="Delete"><br><br>
        </form>

My problem is too big. When I clicked delete button I expected it is delete one folder and one row from my mysql database but nooooo it is delete one folder and all row in mysql database in first page where I can see delete button. Where is the problem I can understood. Can somebody help me?

  • 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-06-17T11:57:37+00:00Added an answer on June 17, 2026 at 11:57 am

    You’re calling delete_row() from within a loop that iterates over the resultset of SELECT ... FROM files WHERE username = '$userfile' restricted only by the LIMIT clause.

    Whilst remove_directory() is also called repeatedly from within that loop, it is always called with the same argument: 'files/'.basename($_POST['dir']).

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

Sidebar

Related Questions

<?php function remove_directory($directory) { if (is_dir($directory) === true) { $contents = scandir($directory); unset($contents[0], $contents[1]);
How can i use opendir function to read the directory list of a remote
how to remove function that bound to member function of this object : std::vector<std::function<void(int)>>
I have the following function to remove a DOM element div, $('#emDiv').on(click, ':button[data-emp-del=true]', function
I'm trying to use a PHP function to read a server directory for images.
I have this function to make a directory on a remote server using ftp,
Calls to PHP's is_readable() function are returning false on a directory that is readable
I have a function which is merging certain files from a directory def merge(path):
I have the function below that copies a file in a directory and recreate
The View.remove() function in backbone js removes the container element of the view itself

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.