POST not receiving form input

Asked

Viewed 66 times

0

In my code I have this form on HTML but in giving Ubmit in the form mine POST of PHP does not receive the image input.

code HTML down below:

 <form action="/news/createsubmit" method="post" enctype="multipart/form-data">
        <div class="col-sm-8">
        <div class="form-group row">
            <div class="custom-file">
                 <input type="file" name="pic" accept="image/*" id="customFile" required>
                 <label class="custom-file-label" for="customFile">Choose an Image</label>
            </div>
        </div>
        </div>
                <div class="col-sm-8"> 
        <div class="form-group row">
            <label for="colFormLabel" class="col-sm-0 col-form-label"></label>
                <input type="text" name="author" class="form-control" id="colFormLabel" placeholder="Autor" required>
            </div>
        </div>
</form>

Below follows print of $_POST in PHP:

Array
(
    [author] => dd

)

  • Select your PHP code that receives the form ?

1 answer

1


You must find the entrance of the type file, in your case, images, using the global matrix $_FILES, nay $_POST.

See this page for more background:
https://www.php.net/manual/en/features.file-upload.post-method.php
https://www.php.net/manual/en/reserved.variables.files.php


DEMO:

index_test.php:

<form action="createsubmit.php" method="post" enctype="multipart/form-data">
        <div class="col-sm-8">
        <div class="form-group row">
            <div class="custom-file">
                 <input type="file" name="pic" accept="image/*" id="customFile" required>
                 <label class="custom-file-label" for="customFile">Choose an Image</label>
            </div>
        </div>
        </div>
                <div class="col-sm-8"> 
        <div class="form-group row">
            <label for="colFormLabel" class="col-sm-0 col-form-label"></label>
                <input type="text" name="author" class="form-control" id="colFormLabel" placeholder="Autor" required>
            </div>
        </div>
        <button>Enviar</button>
</form>

createsubmit.php:

<?php
var_dump($_POST);
var_dump($_FILES);
var_dump($_FILES['pic']);

Exit:

etc\createsubmit.php:4:
array (size=1)
  'author' => string 'adfasd' (length=6)
etc\createsubmit.php:5:
array (size=1)
  'pic' => 
    array (size=5)
      'name' => string 'img077.jpg' (length=10)
      'type' => string 'image/jpeg' (length=10)
      'tmp_name' => string 'C:\wamp64\tmp\php4CF9.tmp' (length=25)
      'error' => int 0
      'size' => int 1611653
etc\createsubmit.php:6:
array (size=5)
  'name' => string 'img077.jpg' (length=10)
  'type' => string 'image/jpeg' (length=10)
  'tmp_name' => string 'C:\wamp64\tmp\php4CF9.tmp' (length=25)
  'error' => int 0
  'size' => int 1611653

Browser other questions tagged

You are not signed in. Login or sign up in order to post.