-1

the form upload files can not be displayed, and this is my form upload code

<?php
$imageinfo = getimagesize($_FILES['img']['tmp_name']);
if($imageinfo['mime'] != 'image/gif' && $imageinfo['mime'] != 'image/jpeg') {
echo "<center><br>Sorry, we only accept GIF and JPEG images</br><br>param name: img<br>u can upload 
with CSRF";
exit;
}
$uploaddir = 'ex/';
$uploadfile = $uploaddir . basename($_FILES['img']['name']);
if (move_uploaded_file($_FILES['img']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "File uploading failed.\n";
}?>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" size="20" name="img" />
<input type="submit" name="upload" value="Upload" />
</form>

the result is

Sorry, we only accept GIF and JPEG images
param name: img
u can upload with CSRF

i want to display form upload files

  • What type of file are you uploading? What's the value of `$imageinfo['mime']`? – showdev Aug 14 '20 at 05:03
  • Start by checking what $_FILES actually contains, make a `var_dump` debug output of it at the very start of your script. – CBroe Aug 14 '20 at 07:18

1 Answers1

1

This will work you should specify correct path

<?php
   if($_SERVER["REQUEST_METHOD"] == "POST"){
      $imageinfo = getimagesize($_FILES['img']['tmp_name']);
      if($imageinfo['mime'] != 'image/gif' && $imageinfo['mime'] != 'image/jpeg') {
         echo "<center><br>Sorry, we only accept GIF and JPEG images</b><br>param name: img<br>u can upload 
         with CSRF";
         exit;
      }
      else{
         $uploaddir = '../path-to-move/';
         $uploadfile = $uploaddir . basename($_FILES['img']['name']);
         if (move_uploaded_file($_FILES['img']['tmp_name'], $uploadfile)) {
            echo "File is valid, and was successfully uploaded.\n";
         } else {
            echo "File uploading failed.\n";
         }
      }
}?>
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method="post" enctype="multipart/form-data">
<input type="file" size="20" name="img" />
<input type="submit" name="upload" value="Upload" />
Mohanasundar
  • 157
  • 1
  • 3
  • 13
  • A little explanation might be helpful. For example, see [Is it a good practice to use an empty URL for a HTML form's action attribute?](https://stackoverflow.com/questions/1131781/is-it-a-good-practice-to-use-an-empty-url-for-a-html-forms-action-attribute-a) – showdev Aug 14 '20 at 04:16
  • can't work bro, the form uploads still can not be displayed – buaya laut Aug 14 '20 at 04:32