0

With a .php file of the following content

<!DOCTYPE html>
<html lang="en">
<body>
<?php
    $filename="";
    if($_SERVER['REQUEST_METHOD'] == 'POST') {
        echo "isset post submit: "  .(isset($_POST['submit'])?"true":"false");
        if(isset($_POST['submit']))
        {
            $filename=$_FILES["local_med"]["name"];
            echo "<p>file: " .$filename;
        }
    } // POST
?>

    <h1>Upload File</h1>
    <form method="POST" enctype="multipart/form-data" >
        <input type="file" id="local_med" name="local_med"  required="true"
            accept="image/png, video/mp4"/>
        <br>
        <button type="submit" name="submit"> Submit </button>
    </form>
</body>
</html>

If I select a .png file and click on the Submit button, I get output

isset post submit: true
file: age.png

However, if a .mp4 file is selected instead, I get output

isset post submit: false

What could the mistake be?

Update: tried to use Developer's tool to check payload. However, the tab is not there. No payload tab

Update 2: tried on Firefox. I am getting something. Payload in Firefox

sofname
  • 429
  • 1
  • 5
  • 20
  • 1
    Are you certain that's what is happening? The implication seems to be that the form fields weren't posted properly in that scenario. Use your browser's network tool to see what is actually sent in the payload when you submit the form with the mp4 – ADyson Oct 11 '22 at 19:47
  • @ADyson Thanks for the suggestion. Tried on Opera 91.0.4516.20 and Chrome 106.0.5249.103. Both would not show the "payload" tab. – sofname Oct 11 '22 at 20:46
  • Hm I think that might be an issue with Chrome-based browsers when sending binary file data. Try Firefox, if I remember rightly its dev tools work better in that scenario. – ADyson Oct 11 '22 at 20:48
  • @ADyson Tried Firefox. I am getting the payload information under Request tab. – sofname Oct 11 '22 at 20:56
  • And it all looks normal? Does it show the submit value as well as the file? You didn't show that bit in the picture. – ADyson Oct 11 '22 at 20:57
  • The output of submitting a .mp4 file is still wrong ("isset post submit: false"). There's lots of those code in the payload field, so I searched in it, but "submit" is NOT found. – sofname Oct 11 '22 at 21:02
  • 1
    How big was the file you tried to submit? – ADyson Oct 11 '22 at 21:07
  • Close to 60MB. Could that be the problem? I should try a smaller one then. – sofname Oct 11 '22 at 21:09
  • Possibly. What's the file upload size limit in your PHP settings? – ADyson Oct 11 '22 at 21:10
  • @ADyson The problems is the size limit. I tried with a very small file and it worked fine. I don't know my PHP setting about the upload size yet. I will find the limit and try again. Thanks a lot! -- BTW, browser would not warn about the size limit. Is there a way to let the browser warn about that? – sofname Oct 11 '22 at 21:23
  • You can check it from the client-side with a bit of Javascript - see something like https://stackoverflow.com/questions/5697605/limit-the-size-of-a-file-upload-html-input-element – ADyson Oct 11 '22 at 21:29

0 Answers0