-1

Every time I hit submit button after selecting an image will face the problem "Notice: Undefined index: profile_picture in C:\wamp\www\Test\testImage.php on line 5", and the page print the text not selected which must be display if image is not selected. The index is defined, but why it is behave like this, please help with your suggestions

<?php
$photo = "";
if($_SERVER['REQUEST_METHOD'] == "POST")
{
    $photo = trim(stripslashes($_POST["profile_picture"]));
    if($photo != '')
    {
        //$photo = trim(stripslashes($_POST["profile_picture"]));
        header("Location: success.php");
    }
    else{
        echo 'not selected';
    }
}

?>

<!DOCTYPE html>
<html>
    <body>
        <form name="signup_form" method="post" action="<?php $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
            <input type="file" class="profile_picture" id="profile_picture" name="profile_picture"> </br>
            <input type="submit" name="submit_btn" id="submit_btn" class="submit_btn" value="sign up">
        </form>             
    </body>
</html>
Rahul Sarkar
  • 89
  • 2
  • 10
  • 1
    Also take a look at how to process file uploads [Its the manual, go figure, never would have thought of that](http://php.net/manual/en/features.file-upload.php) – RiggsFolly Jan 11 '16 at 11:47

1 Answers1

1

Files are not posted over $_POST.

They are posted with $_FILES array.

Reference

Pupil
  • 23,834
  • 6
  • 44
  • 66