note 33358 added to features.file-upload
| From: | egreene at form-genie dot com | Date: | Mon, 23 Jun 2003 21:09:45 +0000 |
| Subject: | note 33358 added to features.file-upload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-50899@lists.php.net to get a copy of this message | ||
Save yourself and your server the trouble of uploading an invalid file type...Throw an error on the
client-side using JavaScript (most people have it enabled).
Example:
<script language="JavaScript">
<!--
function checkForm(thisform){
if(thisform.file.value == "" || thisform.file.value == null) {
alert("Please select a file to upload");
thisform.file.focus();
thisform.file.select();
return false;
} else {
validformFile = /(.jpg|.JPG|.gif|.GIF)$/;
if(!validformFile.test(thisform.file.value)){
alert("Only PDF files are supported. Please try again");
thisform.file.focus();
thisform.file.select();
return false;
}
}
return true;
}
//-->
</script>
<form name="newform" action="_URL_" method="post"
onSubmit="return checkForm(this)" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="100000">
...
</form>
----
Manual Page -- http://www.php.net/manual/en/features.file-upload.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33358
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33358&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33358&report=yes