Example of Ajax file upload effect implemented by iframe

Time:2021-7-27
Copy codeThe code is as follows:
< span style = “font family: Verdana, ‘Ms song’, Arial, Microsoft YaHei, Helvetica, sans serif; font-size: 14px; line-height: 21px; text-align: left; background-color: rgb(255, 254, 247); “> Avascript section</span>

Copy codeThe code is as follows:
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<head>
< title > Ajax file upload ~ ~ < / Title >
</head>
<script>
window.onload=function(){
var form=document.getElementsByTagName(‘form’)[0];
form.onsubmit=function(){
var iframe=document.createElement(‘iframe’);
iframe.src=’do_upload.php’;
var iframe_name=”iframe”+Math.random();
iframe.name=iframe_name;
document.body.appendChild(iframe);
iframe.style.width=’0px’;
iframe.style.height=’0px’;
iframe.frameBorder=’0′;
form.target=iframe_name;
}
}
</script>
<body>
<form enctype=’multipart/form-data’ method=’post’ action=’do_upload.php’>
Please select a file: < input type =’File ‘name =’myfile’ / > < br / >
<input type=’submit’/>
<div id=’msg’></div>
</form>
</body>
</html>

//PHP receiving part

Copy codeThe code is as follows:
<?php
$up_file=$_FILES[‘myFile’];
if($up_file[‘error’]===0){
if(!file_exists(‘./imgs’)){
mkdir(‘./imgs’);
}
$save_name=rand().$up_file[‘name’];
$bool=move_uploaded_file($up_file[‘tmp_name’],”./imgs/$save_name”);
if($bool){
$MSG = ‘upload succeeded!’;
}else{
$MSG = ‘upload failed!’;
}
}
echo
“<script>
var msg=parent.document.getElementById(‘msg’);
msg.innerHTML='<font color=red>$msg</forn>’;
</script>”;
?>

Recommended Today

VBS obtains the operating system and its version number

VBS obtains the operating system and its version number ? 1 2 3 4 5 6 7 8 9 10 11 12 ‘************************************** ‘*by r05e ‘* operating system and its version number ‘************************************** strComputer = “.” Set objWMIService = GetObject(“winmgmts:” _  & “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”) Set colOperatingSystems = objWMIService.ExecQuery _  (“Select * from […]