-1

*****What's my error in brief : ->>>

i am uploading multiple image files at a time , for that i m using POST method to post FILES to uploader.php For my testing purpose i m trying to upload only first file (i.e "allotment"). Now when i select a file and click submit my uploader.php is NOT GETTING THE POSTED "ALLOTMENT" . it shows me error "Undefined index: allotment in C:\wamp\www\Pagination_test\uploder.php on line 11"

    allotment letter : 
    <form enctype="multipart/form-data" action="uploder.php" method="POST" >
    <input type="file" name="allotment"/>
    <br/>
    MH-CET / JEE mains score card<br/>
    <input type="file" name="MH-CET"/>
    <br/><br/>
    SSC Marksheet <br/>
    <input type="file" name="fe_scorecard"><br/><br/>
    .
    .

    //and more uploads likt this ---
    //form ends with -----
    .
    .
     <input type="submit" name="submit">
     </form>

MY uploder.php is :

    <?php
    echo "I M ON PAGE FILE UPLODER";
    include_once ('dbconfig.php');
    include_once("check_login_status.php");

    if(isset($_POST['submit']))
    {    
    echo "FILE is  catched successfully ";

    //to print posted array form POST 
    print_r($_FILES);

    // HERE is error of undifined index "ALLLOTMENT" and from this point code is not running

    if (isset($_POST['allotment'])){

    echo $_POST['allotment']['name'];
    .
    .
    . --- and rest of uploading code (its working fine)--
    .---if ends---
    }

At ifset statement i m getting error of undefined index error for allotment.

what i tried >>

I tried putting ENCTYPE in my from att. I tried PRINT_r to print POSTED array

What i found in print_r >>

    Array ( [allotment] => Array ( [name] => smalllogo.png [type] => image/png [tmp_name] => C:\wamp\tmp\php8756.tmp [error] => 0 [size] => 27252 ) [MH-CET] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 )

means "allotment is posted ". but then why i am getting ths error of undefined index ????? pls help

Akash Varde
  • 83
  • 1
  • 11

1 Answers1

0

Right here was the Error... You are dealing with a File not posted Data.

        // NOT $_POST[] GLOBAL BUT RATHER $_FILES[] GLOBAL
        if (isset($_POST['allotment'])){

        echo $_POST['allotment']['name'];
        .
        .
        . --- and rest of uploading code (its working fine)--
        .---if ends---
        }

This is how it could have been written:

        <?php 
            if (isset($_FILES['allotment'])){  //<== $_FILES NOT $_POST

                echo $_FILES['allotment']['name'];
                .
                .
                . --- and rest of uploading code (its working fine)--
                .---if ends---
            }
Poiz
  • 7,611
  • 2
  • 15
  • 17