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

  • Home
  • SEARCH
  • 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 8344493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:23:32+00:00 2026-06-09T06:23:32+00:00

I am calling a .php file that lies within my ‘uploads’ directory to delete

  • 0

I am calling a .php file that lies within my ‘uploads’ directory to delete from the filesystem. The directories that need to be searched will always be inside “uploads/$_SESSION[’email’]”. This is what I have currently:

<?php

session_start();

require('../mysqli_connect.php'); 


    $old = getcwd(); // Save the current directory
    $new = './'.$_SESSION['email'];
    chdir($new);

    $delpaths = "SELECT `title` FROM `upload` WHERE `upload_id` IN ({$id_array}) AND `owner_id` =". $_SESSION['user_id'];
    $getpaths = mysqli_query($dbc, $delpaths);
    while ($row = mysqli_fetch_array($getpaths, MYSQLI_ASSOC))
    {
        chown($row, 666);

function removeupload() {
$todelete = $row;
unlink($todelete);
chdir($old); 

}

    }


?>
  • 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-09T06:23:33+00:00Added an answer on June 9, 2026 at 6:23 am

    I see a of couple issues here… The first being that $row would be passed back as an array, so simply calling $row won’t give you the desired result (which I’m assuming is the name of the file you’re trying to delete that is stored in your database). $row should be changed to something like:

    chown($row['column_name'], 666); // Where column_name is the name of the file you're trying to delete
    

    The second is that there is nothing being passed to your function. You should rewrite it so that you can pass a couple variables to it so that it executes properly, we’ll add $filename and $old.

    function removeupload($filename, $old) {
        unlink($filename);
        chdir($old); 
    }    
    

    Finally, you should define this function outside of your while loop, usually at the beginning of the page, and call it when you’d want the desired effect to happen.

    Your final code should should look something like this.

    <?php
        //Start the session
        session_start();
    
        //Include the connection script
        require('../mysqli_connect.php'); 
    
        //Build the file deletion function
        function removeupload($filename, $old) {
            unlink($filename);
            chdir($old); 
        }  
    
        $old = getcwd(); // Save the current directory
        $new = './'.$_SESSION['email'];
        chdir($new);
    
        $delpaths = "SELECT `title` FROM `upload` WHERE `upload_id` IN ({$id_array}) AND `owner_id` =". $_SESSION['user_id'];
        $getpaths = mysqli_query($dbc, $delpaths);
    
        while ($row = mysqli_fetch_array($getpaths, MYSQLI_ASSOC)) {
            chown($row['column_name'], 666); //This $row column holds the file name, whatever you've called it in your database.
    
            //Now call the function and pass the variables to it
            removeupload($row['column_name'], $old);
    
        }
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm calling some JavaScript from within my PHP code, but I want the second
from my understanding, require pastes code into the calling php file. what if you
I would need to create a php file that will do some work on
Hy! I want to make a autosuggest from my php file that returns a
I'd like to reference files from the root directory even if, the file that
I have an exe file that I'm calling through php using the 'system' command.
I have an exe file that I'm calling through php using the 'system' command.
I am calling my makewindows function from a PHP file like so: echo <a
I have a form that's calling a Post a .php file, which i though
Is there any way to include php file using require and calling a php

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.