Skip to content

Instantly share code, notes, and snippets.

@tistre
Last active August 29, 2015 14:10
Show Gist options
  • Save tistre/31fe98a7780f75fdae23 to your computer and use it in GitHub Desktop.
Save tistre/31fe98a7780f75fdae23 to your computer and use it in GitHub Desktop.
Internet Explorer 9 and 10 do not submit the form if a file input click has been triggered
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
</head>
<body>
<?php
if ($_SERVER[ 'REQUEST_METHOD' ] === 'POST')
{
if (isset($_FILES[ 'file' ]) && isset($_FILES[ 'file' ][ 'tmp_name' ]) && is_uploaded_file($_FILES[ 'file' ][ 'tmp_name' ]))
{
printf('%s: %s has been uploaded', time(), htmlspecialchars($_FILES[ 'file' ][ 'name' ]));
unlink($_FILES[ 'file' ][ 'tmp_name' ]);
}
else
{
printf('%s: No file uploaded', time());
}
}
else
{
?>
<p>Demonstrating special Internet Explorer 9/10 behaviour:</p>
<p>If you click the file input's "Browse" button to choose a file, you can submit the form.</p>
<p>If you click the other button that triggers a click on the file input, IE silently refuses
to submit the form.</p>
<p>Verified in IE 9 and 10. IE 11, Firefox and Google Chrome always submit the form correctly.</p>
<form action="" method="POST" enctype="multipart/form-data" target="upload_target">
<button type="button" onclick="$('#file_input').click()">Trigger a click on file input</button>
<input id="file_input" type="file" multiple="multiple" name="file" />
<input type="submit"/>
</form>
<iframe name="upload_target" src="" width="600" height="300"></iframe>
<?php
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment