0

So I was making an HTML, PHP and ZIP file submission. I expect to upload the file to the directory and showing file info and contents from if. But when I upload an HTML file, the File info shows blank, and it keeps showing contents from else. main page HTML result after upload HTML file PHP Here is the complete code:

HTML

<html>
  <head>
    <title>Submit HTML, PHP File</title>
    <link rel="stylesheet" href="/style.css">
  </head>
  <body>
    <h1>Submit a File to HTMLtest [BETA]</h1>
    <h3>only HTML, PHP, and ZIP files containing files for making a website are allowed.</h3>
    <form action="/HTMLtest/submit-file/submitted.php" method="post">
      <input type="file" name="FileUpload">
      <br>
      <input type="submit" value="Submit">
    </form>
  </body>
</html>

PHP

<html>
  <head>
    <title>Upload File</title>
    <link rel="stylesheet" href="/style.css">
  </head>
  <body>
    <h1>File Info</h1>
    <?php
echo "<b>File Name: </b><p>". $_FILES['FileUpload']['name'] . "</p><br>";
echo "<b>File Type: </b><p>". $_FILES['FileUpload']['type'] . "</p><br>";
echo "<b>File Location: </b>". $_FILES['FileUpload']['tmp_name']. "</p><br>";
echo "<b>File Size: </b><p>". $_FILES['FileUpload']['size']; 
echo " B";
echo "</p><br><br>";

$FileSource = $_FILES['FileUpload']['tmp_name'];
$FileUpload = '/HTMLtest/submit-file/pending/'. $_FILES['FileUpload']['name'];
  
if (($_FILES['FileUpload']['type'] == "text/html") or ($_FILES['FileUpload']['type'] == "text/php") or ($_FILES['FileUpload']['type'] == "application/zip"))
{
  copy($FileSource,$FileUpload);
  echo "<h1>Upload Complete!</h1>";
  echo "<h3>Your file is submitted and it's currently pending approval</h3>";
}
else
{
  echo "<h3>Sorry, you can only upload HTML, PHP and ZIP files. ZIP files must contain HTML and PHP files.</h3>";
}
?>
<br><br>
    <a href="/HTMLtest/submit-file/">Upload another file</a>
  </body>
</html>

How could I fix this?

  • Why the verbose checks on `$_FILES['FileUpload']['type']`? Why not `in_array()`? Did you dump out your `$_FILES` array upon submission to see what data is being submitted? Does your application use url redirecting? Is this causing the submission payload to be dropped? – mickmackusa Mar 23 '22 at 02:09
  • 2
    Does this answer your question? [Upload a file using PHP](https://stackoverflow.com/questions/35253550/upload-a-file-using-php) Your `
    ` tag needs `enctype="multipart/form-data"`.
    – kmoser Mar 23 '22 at 02:15
  • @kmoser No it doesn't. It still shows the exact same thing. – Calvin Tanuri Mar 23 '22 at 02:20
  • @pro70 how did adding [enctype="multipart/form-data"](https://stackoverflow.com/questions/4526273/what-does-enctype-multipart-form-data-mean) to your form not help? Its exactly for allowing files to be sent within a post request? Please update your question with your exact code so we can help you further. – Definitely not Rafal Mar 23 '22 at 06:10
  • Why did you change the form's `enctype` to `form/multipart` when it should be `multipart/form-data`? Any why don't you `echo $_FILES['FileUpload']['type'];` to see what the value is? – kmoser Mar 28 '22 at 03:47

0 Answers0