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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:57:26+00:00 2026-06-03T01:57:26+00:00

I am trying to append a the variable imagename but instead of displaying a

  • 0

I am trying to append a the variable imagename but instead of displaying a file name, it is appending numbers ‘0’ then break then ‘1’. I want to know why is it appending these numbers and not the file names? The imagename variable loops through the imageNameArray variable which contains a $_SESSION variable which retrieves the name of the files which have been uploaded and that $_SESSION variable is retrieved from the php script where the files are uploaded.

Below is the javascript code where the appending occurs:

  function stopImageUpload(success){

var imageNameArray = <?php echo json_encode(isset($_SESSION ['fileImage']) ? $_SESSION ['fileImage'] : null); ?>;
 var result = '';



if (success == 1){
result = '<span class="msg">The file was uploaded successfully!</span><br/><br/>';
for (imagename in imageNameArray)
            {
$('.listImage').append(imageNameArray[imagename]+ '<br/>');

             }

              }
 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 and where the $_SESSION variable retrieve its file name:

 <?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;


            }
        }

    }

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

    ?>

<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-03T01:57:27+00:00Added an answer on June 3, 2026 at 1:57 am

    because you’re using a for in loop on an array, imageName will be equal to the array indeces, not its values. Much like for (i in window),where i will list all methods and properties of the window object.

    Since this is an array, I strongly recommend you use a for(i=0;i<arr.length;i++) type of loop, because it’s just safer… in both cases you will need to replace

    $('.listImage').append(imagename + '<br/>');
    

    with

    $('.listImage').append(imageNameArray[imagename]+ '<br/>');
    

    EDIT

    The for loop probably din’t work for you because I left out a bit, because I thought it to be obvious. Unfortunately, obvious things are easy to overlook… as Greg pointed out to me (thx m8) :

    $('.listImage').append(imageNameArray[i]+ '<br/>');
    

    if you use the for(i…) style loop. I’ll just add the full loop for clarity:

    for(var i=0;i<imageNameArray.length;i++)
    {
        $('.listImage').append(imageNameArray[i]+ '<br/>');
    }
    

    To help you further in finding out what might be causing the problem with only one img name showing up, add this right before the loop begins: console.log(imageArrayName); and look at your console. Does the array contain more than 1 element? what does it say? While you’re at it, try adding this line, too: console.log((imageArray instanceof Array ? 'for' : 'for-in'));. Add this line anywhere in the JavaScript function you posted, but outside the loop to avoid cluttering your console all to much…

    Let me know what you find out

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

Sidebar

Related Questions

I'm trying to append some text to a variable in a Makefile for HP-UX's
So I'm trying to access the variable 'username' from another class and append it
I am trying to append to a log file, using HTML tables format for
I'm trying to append items to a QList at runtime, but I'm running on
I'm trying to have a user-created variable processed on the server and then sent
I'm trying to have a variable store the HTML in a div tag, but
Trying to load a file into python. It's a very big file (1.5Gb), but
I am trying to append a lengthy list of rows to the same variable.
Hello i am trying to modify the variable popText but failing on the ajax
I am appending a variable from an input to a li. I want to

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.