File upload using HTML form on Git Bash server

The following code was used but it failed to transfer the image file to PHP file upload.php
Could it be the php.ini is not setup to allow file uploads.

<!DOCTYPE html>
<html>
<body>
<form enctype="multipart/form-data" action="upload.php" method="POST">
  <input type="hidden" accept=".gif, .jpg, .png" />
  <input type="hidden" name="MAX_FILE_SIZE" value="500000" />

  Select image to upload:
  <input type="file" name="fileToUpload" id="fileToUpload">

  <input type="submit" value="Upload Image" name="submit">
</form>

</body>
</html>
1 Like

Can we see upload.php?

Should not the accept attribute be on the file input?

1 Like

I will be interested too to make some learning.

Upload.php used to check what was happening is as follows:

<?php

echo "here";
 $filename = $_POST['fileToUpload'];

if(isset($_POST['fileToUpload'])){
    $filename = $_POST['fileToUpload'];
	echo $filename;
	echo "here 1";
}
if(isset($filename)){ 
    echo $filename;
	echo "here 2";
}
?>

Wouldn’t the file details be in $_FILES rather than $_POST?

1 Like

Yes the file details would be there but surely the $_POST [ ] is needed to get the information from the FORM first. This is not the complete file I would, it is just testing for transfer of details from the FORM which seems not to be working. One of the things I want help with is checking the PHP.ini file.

I haven’t done much with it, so I’m not sure whether that specific field would also be included in $_POST. You could find out easily by just using var_dump($_POST) and var_dump($FILES) as I’m sure you now.

ETA: I just tried it. For this form:

<!DOCTYPE html>
<html lang="en-gb">
<body>
<form method="post" action="uploadtest.php" enctype="multipart/form-data">
<input type="file" name="myfile">
<input type="text" name="myfiletext">
<input type="submit">
</form>
</body>
</html>

my two var_dumps ($_POST then $_FILES) gives this:

C:\wamp64\www\sitepoint\uploadtest.php:3:
array (size=1)
  'myfiletext' => string 'test' (length=4)
C:\wamp64\www\sitepoint\uploadtest.php:4:
array (size=1)
  'myfile' => 
    array (size=5)
      'name' => string 'Annotation 2020-04-14 103839.jpg' (length=32)
      'type' => string 'image/jpeg' (length=10)
      'tmp_name' => string 'C:\wamp64\tmp\phpBF9A.tmp' (length=25)
      'error' => int 0
      'size' => int 46934

So it seems that no, there shouldn’t be anything in $_POST['fileToUpload'], it’s all in $_FILES.

The other inputs should be in $_POST, but the actual file upload should be in $_FILES.

But what other info are you getting from the form? The only other inputs are hidden ones, where you set the values yourself. I don’t see the point of those at all.