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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:28:53+00:00 2026-06-02T17:28:53+00:00

I have this code below and the problem is that it is not uploading

  • 0

I have this code below and the problem is that it is not uploading the file and the call back javascript function at the bottom isn’t displaying the result. Now before I entered in the if isset ($_POST[fileImage’])… code, and the $_SESSION['fileImage']['name'] = $_FILES['fileImage']['name'];, then the files uploaded perfectly.But with those 2 pieces of code, it has stopped the uploading from happening.

So I believe the problem is that the code above I have used have been placed in the wrong places. How can the code below be placed correctly in the right places for the uploading to start working again?

Below is the code which is suppose to upload the files but fails:

  <?php

    $result = 0;

       if (isset($_POST['fileImage']) && ((($_FILES["fileImage"]["type"] == "image/gif")
    || ($_FILES["fileImage"]["type"] == "image/jpeg")
    || ($_FILES["fileImage"]["type"] == "image/pjpeg")
    || ($_FILES["fileImage"]["type"] == "image/jpg")
    || ($_FILES["fileImage"]["type"] == "image/png")
    || ($_FILES["fileImage"]["type"] == "image/tif"))){

    if( file_exists("ImageFiles/".$_FILES['fileImage']['name'])) {  

        $parts = explode(".",$_FILES['fileImage']['name']);
        $ext = array_pop($parts);
        $base = implode(".",$parts);
        $n = 2;

        while( file_exists("ImageFiles/".$base."_".$n.".".$ext)) $n++;
        $_FILES['fileImage']['name'] = $base."_".$n.".".$ext;

        move_uploaded_file($_FILES["fileImage"]["tmp_name"], 
        "ImageFiles/" . $_FILES["fileImage"]["name"]);
        $result = 1;

    }
        else
          {
          move_uploaded_file($_FILES["fileImage"]["tmp_name"],
          "ImageFiles/" . $_FILES["fileImage"]["name"]);
          $result = 1;

          }

          ?>

<script language="javascript" type="text/javascript">
window.top.stopImageUpload(<?php echo $result;?>);
</script>   

          <?php

    }

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

    ?>
  • 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-02T17:28:55+00:00Added an answer on June 2, 2026 at 5:28 pm

    I see that you are using using both $_FILES["fileImage"] and $_POST['fileImage'] and am not sure that is correct .

    The way you have also written does not make it clean enough to easily identify errors .. you can use this

    Try

    <?php
    
    $result = 0;
    $errors = array ();
    $dirImage = "ImageFiles/";
    
    $allowedTypes = array (
            "image/jpeg",
            "image/gif",
            "image/pjpeg",
            "image/jpg",
            "image/png",
            "image/tif" 
    );
    
    if (isset ( $_FILES ['fileImage'] ) && $_FILES ["fileImage"] ["error"] == UPLOAD_ERR_OK) {
    
        $fileName = $_FILES ['fileImage'] ['name'];
        $fileSize = $_FILES ['fileImage'] ['size'];
        $fileTemp = $_FILES ['fileImage'] ['tmp_name'];
        $fileType = $_FILES ['fileImage'] ['type'];
    
        $fileExt = pathinfo ( $fileName, PATHINFO_EXTENSION );
        $fileExt = strtolower ( $fileExt );
    
        if (empty ( $fileName ))
            continue;
    
        if (! in_array ( $fileType, $allowedTypes )) {
            $errors [] = "File Type is not accepted";
    
        }
    
        if(!is_writable($dirImage ))
        {
            $errors [] = "File Destination not writeable";
        }
    
    
        $fileDst = $dirImage . DIRECTORY_SEPARATOR . $fileName;
        $filePrifix = basename ( $fileName, "." . $fileExt );
        $i = 0;
        while ( file_exists ( $fileDst ) ) {
            $i ++;
            $fileDst = $dirImage . DIRECTORY_SEPARATOR . $filePrifix . "_" . $i . "." . $fileExt;
    
        }
        // Move the file
    
        if (count ( $errors ) == 0) {
            if (move_uploaded_file ( $fileTemp, $fileDst )) {
                $result = 1;
            }
        }
    
    }
    
    $_SESSION ['fileImage'] ['name'] = $_FILES ['fileImage'] ['name'];
    ?>
    

    Please note that the errors are stored in $errors variable and what i advice is for you ro convert it to json can call it via your JavaScript code

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

Sidebar

Related Questions

I have this javascript code below that uses jquery, it is suppoed to be
I am having a problem, on a blog I have this javascript code below
I have a data that looks like this . And my code below simply
I have this code below. I randomly ran across that it will work if
I have this code below. As you can see I am passing two variables
I have this code below: $insert = array(); for ($i = 1, $n =
I have this below code and it work fine header (content-type: text/xml); $xml =
I have this snippet of code below. I want to pass the value of
I have this kind of code below, how can I bind the visibility of
I have written grammar for a language (sample code below) //this is a procedure

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.