FileUp resides on the server and cannot do any kind of validation until the HTTP request containing the uploaded file(s) has reached the server. Therefore, if you want to do any validation of the upload before it begins, you must do so on the client machine. If you are using FileUp Professional which includes our client-side controls XFile and JFile, you can perform a wide variety of validation and filtering functions before the upload begins. This article applies to file transfer applications which are using FileUp Standard Edition on the server and only a regular HTML form with <INPUT type="file"> fields on the client.
Browsers, for security reasons, do not permit programmatic access to the file input field for tasks such as pre-setting the path of the file to be uploaded. However, you can perform basic validation to make sure the field is not empty through client-side JavaScript or VBScript.
The validation script in the following html form loops through the file fields and prompts the user if any are blank. It then returns the focus to the blank file field:
<html>
<head>
<title>Upload Form</title>
<script type="text/javascript" language="javascript">
function validate(f) {
var fieldname = ['File1' , 'File2' , 'File3'];
for (var i=0; i<f['files[]'].length; ++i)
if (!f['files[]'][i].value) {
alert('Please select a file to upload from the "' + fieldname[i] + '" field.');
f['files[]'][i].focus();
return false;
}
return true;
}
</script>
</head>
<body>
<form action="formresp.asp" method="post" name="uploadform" enctype="multipart/form-data"
onsubmit="return validate(this)">
File1: <input type="file" name="files[]"><BR>
File2: <input type="file" name="files[]"><BR>
File3: <input type="file" name="files[]"><BR><BR>
<input type="submit" value="Upload">
</form>
</body>
</html>
The above HTML form is attached to this article for your convenience.
|