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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:39:49+00:00 2026-05-22T22:39:49+00:00

I have a class with a couple of methods deleteUploadedFile() and currentUploadedFiles() . currentUploadedFiles(),

  • 0

I have a class with a couple of methods

deleteUploadedFile() and currentUploadedFiles().

currentUploadedFiles(), basically loops over a session array and displays it on screen, simple as. Code sample:

function currentUploadedFiles()
    {
        if(isset($_SESSION['fileArray']) && $this->count > 0)
        {
            echo '<p style="clear:both">Current files uploaded list:</p>';
            echo '<ol>';

            foreach($_SESSION['fileListing'] as $key => $value )
            {
                echo '<li>'. $value .' <a href="'.$_SERVER["PHP_SELF"].'?id='.$key.'">[Remove File]</a></li>';
            }

            echo "</ol>\n\r";
            echo "<p> Current file size allowance: ". $this->_returnRemainingSessionFileSize() ." of 8 MB";
        } else {
            echo '<p style="clear:both">No files have been uploaded yet</p>';
        }    

        if($this->deleteUploadedFile() === true)
        {
            echo '<p>File has now been deleted from our records.</p>';
        }
    }

the deleteUploadedFile() method, basically when form is submitted it deletes file from the server and removes the entry from the session array. Sample code:

function deleteUploadedFile()
    {
        (int) $id = $_GET['id'];
        (bool) $deleted = false;

        if (file_exists($this->target_path.'/'.$_SESSION['fileArray'][$id]))
        {

            $_SESSION['fileSize'] -= $this->_checkSessionFileSize($id);

            if (unlink($this->target_path.'/'.$_SESSION['fileArray'][$id]))
            {

                $deleted = true; //'<p>File has now been deleted from our records.</p>';
                unset($_SESSION['fileArray'][$id]);
                unset($_SESSION['fileListing'][$id]);


            }

        }

        return $deleted;

    }

my controller, basically checks if file id# isset, then checks if the array id# isset, then calls the deleteUploadedFile() method and then calls the currentUploadedFiles() method.

Question is, why when I var_dump $deleted var in deleteUploadedFile() I get bool(true) but inside the currentUploadedFiles() method I get bool(false). Sounds like I’m messing up the scope somehow?

  • 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-22T22:39:50+00:00Added an answer on May 22, 2026 at 10:39 pm

    Looks like $deleted is in the local scope of the delete function.

    Something like the following should work.

    class theClass
    {
        function __construct()
        {
            $this->deleted = false
        }
    
        function delete()
        {
            $this->deleted = true;
        }
    
        function upload()
        {
            var_dump($this->deleted);
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a abstract base C# class with a couple of methods that has
I have a template class in which I am specializing a couple of methods.
I have a domain class containing a couple of fields. I can access them
I have a template class that is only valid for couple of template parameters:
I have a couple of Divs which I style using a class and an
So I had a couple of methods in my main class that used a
I have an array of pointers to a base class, so that I can
In appllication controller i have couple of methods that works with requested controller and
I have couple of helper methods added to the existing classes, and i want
I have a couple of questions about the way I call methods in EL.

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.