Menu
This php file I have has this in it:
if ($_FILES[“fileToUpload”][“size”] > 5000) {
header(“Location:
exit;
}
which processes if the file is too large, correct?
When the user gets sent back to
how can the message “too large” be displayed?
I look forward to any guidance,
<i>
</i><!DOCTYPE html>
<html>
<head>
<title>test</title>
<style type="text/css">
.error { color: red; }
</style>
</head>
<body>
<h1>Test</h1>
<p id="foo" class="error"></p>
<p>Form stuff here...</p>
<script type="text/javascript">
const urlParams = new URLSearchParams(window.location.search);
const error = urlParams.get('error');
if(error == 'too_large') {
document.getElementById('foo').innerHTML = "File is too large.";
}
</script>
</body>
</html>
<p id="foo" class="error"></p>
getElementById()
?error=too_large
``<i>
</i>if ($_FILES["fileToUpload"]["size"] > 5000) {
header("Location: https://www.example.com/form_page.html?error=too_large);
exit;
}<i>
</i>
`</CODE>
connects/triggers your posted code:
<CODE>
`<i>
</i> <p id="foo" class="error"></p>
<script type="text/javascript">
const urlParams = new URLSearchParams(window.location.search);
const error = urlParams.get('error');
if(error == 'too_large') {
document.getElementById('foo').innerHTML = "File is too large.";
}
</script><i>
</i>
``
<!DOCTYPE html><br/>
<html><br/>
<head><br/>
<title>test</title><br/>
<style type="text/css"><br/>
.error { color: red; }<br/>
</style><br/>
</head><br/>
<body><br/>
<h1>Test</h1><br/>
<?php<br/>
if (isset ($_GET['error']))<br/>
{<br/>
if ($_GET['error'] == "too_large")<br/>
$err = "File is too large";<br/>
else /* handle other error messages */<br/>
;<br/>
printf ("<p class='error'>%s</p>",$err);<br/>
} <br/>
?><br/>
<p>Form stuff here...</p><br/>
</body><br/>
</html>
.php
.html
``<i>
</i><?php
if (isset ($_GET['error']))
{
if ($_GET['error'] == "too_large")
$err = "File is too large";
else /* handle other error messages */
;
printf ("<p class='error'>%s</p>",$err);
}
?><i>
</i>
`</CODE>
and reload the page I see this:
<CODE>
`<i>
</i>%s
",$err);
}
?><i>
</i>
``
<form action="..//uploadM.php" method="post" enctype="multipart/form-data"> ETC...
``<i>
</i><?php
$target_dir = "uploadM/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
ETC...<i>
</i>
``
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<title>File Upload</title>
<style>
#overlay {
/* the overlay should fill the browser window */
width: 100vw;
height: 100vh;
display: none;
position: fixed;
background-color: white;
left: 0;
top: 0;
/* additonal styling to center the text or icon */
align-items: center;
justify-content: center;
}
</style>
</head>
<body>
<i> </i><form id="uploadForm" method="post" action="upload.php" enctype="multipart/form-data">
<i> </i> <input type="file" name="file">
<i> </i> <input type="submit">
<i> </i></form>
<i> </i><!-- overlay displaying a busy message or icon -->
<i> </i><div id="overlay">Uploading, please wait ...</div>
<i> </i><script>
<i> </i> // add an event listener for submit
<i> </i> document.getElementById('uploadForm').addEventListener('submit', function () {
<i> </i> // the form was submitted, make overlay visible
<i> </i> document.getElementById('overlay').style.display = 'flex';
<i> </i> });
<i> </i></script>
</body>
</html>
0.1.9 — BETA 4.26