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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:13:17+00:00 2026-06-02T19:13:17+00:00

I have a problem where everytime I refresh the browser, I want the array

  • 0

I have a problem where everytime I refresh the browser, I want the array which contians a $_SESSION variable to go back to being blank. At moment lets say I uploaded 2 files and then refresh browser, when I upload another file, it shows the name of the previous files uploaded when it shouldn’t. How can I get the array and session variable to go back to being blank if browser is refreshed?

Below is code:

  function stopImageUpload(success){

          var imageNameArray = new Array();
// WHEN PAGE IS REFRESH, ARRAY SHOULD GO BACK TO BEING BLANK

 imageNameArray = <?php echo json_encode(isset($_FILES ['fileImage']['name']) ? $_FILES ['fileImage']['name'] : null); ?>;
//RETRIEVES THE SESSION VARIABLE FROM THE PHP SCRIPT OF THE FILE NAMES WHICH HAVE BEEN UPLOADED

          var result = '';



          if (success == 1){
             result = '<span class="msg">The file was uploaded successfully!</span><br/><br/>';

                for(var i=0;i<imageNameArray.length;i++)  //LOOP THROUGH ALL UPLOADED FILE NAMES
        {
             $('.listImage').append(imageNameArray[i]+ '<br/>');//APPEND FILE NAME

         }

          }
          else {
             result = '<span class="emsg">There was an error during file upload!</span><br/><br/>';
          }

    return true;

    }

Below is the php script where it uploads a file which is on another page from the javascript function above:

<?php

    session_start();

    $result = 0;
    $errors = array ();
    $dirImage = "ImageFiles/";


if (isset ( $_FILES ['fileImage'] ) && $_FILES ["fileImage"] ["error"] == UPLOAD_ERR_OK) {

$fileName = $_FILES ['fileImage'] ['name'];

$fileExt = pathinfo ( $fileName, PATHINFO_EXTENSION );
$fileExt = strtolower ( $fileExt );


$fileDst = $dirImage . DIRECTORY_SEPARATOR . $fileName;

        if (count ( $errors ) == 0) {
            if (move_uploaded_file ( $fileTemp, $fileDst )) {
                $result = 1;


            }
        }

    }

    ?>

<script language="javascript" type="text/javascript">window.top.stopImageUpload(<?php echo $result;?>);</script>
  • 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-02T19:13:18+00:00Added an answer on June 2, 2026 at 7:13 pm

    Although I agree with the comment of @Reza Sanaie, you can solve your particular problem by unsetting the variable after a successful upload:

         if (success == 1)
         {
             result = '<span class="msg">The file was uploaded successfully!</span><br/><br/>';
    
             for(var i=0;i<imageNameArray.length;i++)  //LOOP THROUGH ALL UPLOADED FILE NAMES
             {
                 $('.listImage').append(imageNameArray[i]+ '<br/>');//APPEND FILE NAME
    
             }
    
             $_SESSION ['fileImage'] = NULL; // or use unset()
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem with fancybox. I want to write a function that will run
I have problem with cakephp's Session->write method. If I set a value like $_SESSION['..']
I have problem with HTTP headers, they're encoded in ASCII and I want to
I have some problems with OnTouchListener . I want that everytime when user touch
I've encountered a weird problem. Everytime I refresh the page, IsPostBack is false. To
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
i have problem with autorotate on iphone i set up in all classes -
I have problem with displaying adsense ads in ie7 google adsense adds an iframe
i have problem to correctly bind data to WPF Chart. When i'm setting ItemsSource
I have problem with Oracle 9.2 and JMS. I created PL/SQL routine to send

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.