HTML page code
| The code is as follows |
Copy Code |
|
<iframe name= "iframe" style= "Display:none" ></iframe>
<form action= "action.php" method= "post" enctype= "Multipart/form-data" target= "iframe" >
</form>
function Errors (msg)
{
Alert (msg);
} |
action.php page
| The code is as follows |
Copy Code |
|
if ($input = = ") {
echo "<script>parent.errors (' this is a test!!! ');</script> ";
Exit
} |
So that when we submit it will pop up this is a test!!! And if you want to have a nice pop-up layer effect we can put
function Errors (msg)
{
Alert (msg);
}
function into the JS pop-up layer can be.
example, using IFRAME imitate Ajax file upload
HTML page
| The code is as follows |
Copy Code |
<body>
<form action= "upload.jsp" id= "Form1" Name= "Form1" enctype=
Data "method=" POST "target=" Hidden_frame ">
<input type= "File" id= "file" name= "file" style= "width:450" >
<inputtype= "Submit" value= "Upload file" >
</form>
<iframe name= "Hidden_frame" id= "Hidden_frame" style= "Display:none" ></iframe><span id= "MSG" ></ Span>
</body>
<script type= "Text/javascript" >
function Callback (MSG)
{
document.getElementById ("file"). outerHTML = document.getElementById ("file"). outerHTML;
document.getElementById ("msg"). InnerHTML = "<font color=red>" +msg+ "</font>";
}
</script> |
JS Processing page
| The code is as follows |
Copy Code |
|
<%@ page language= "java" contenttype= "text/html; charset=gb2312 "%>
<%@ page import= "Com.jspsmart.upload.SmartUpload"%>
<%
Create a new Smartupload object
Smartupload su = new Smartupload ();
Upload initialization
Su.initialize (PageContext);
Set upload limit
1. Limit the maximum length of each uploaded file.
Su.setmaxfilesize (10000000);
2. Limit the length of the total upload data.
Su.settotalmaxfilesize (20000000);
3. Set the file allowed to upload (by extension limit), only allow doc,txt files.
Su.setallowedfileslist ("Doc,txt,jpg,rar,mid,waw,mp3,gif");
Boolean sign = true;
4. Set the file that prohibits uploading (by extension limit), prohibit uploading files with exe,bat,jsp,htm,html extensions and files with no extension.
try {
Su.setdeniedfileslist ("exe,bat,jsp,htm,html");
Uploading files
Su.upload ();
Save the uploaded file to the specified directory
Su.save ("C:\");
catch (Exception e) {
E.printstacktrace ();
sign = false;
}
if (sign==true)
{
Out.println ("<script>parent.callback (' Upload file Success ') </script>");
}
Else
{
Out.println ("<script>parent.callback (' Upload file error ') </script>");
}
%> |