Copy codeThe Code is as follows:
<Html>
<Head>
<Title> resumable upload of files </title>
<Meta Content-type = "text/html" charset = "UTF-8"/>
<Script type = "text/Webpage effects">
Function startUpload (){
Document. getElementById ('processing'). innerHTML = 'loding ...';
Return true;
}
Function stopUpload (rel ){
Var msg;
Switch (rel ){
Case 0:
Msg = "uploaded ";
Break;
Case 1:
Msg = "the number of uploaded files exceeds the limit ";
Break;
Case 2:
Msg = "only image files can be uploaded ";
Break;
Default:
Msg = "failed to upload the file ";
}
Document. getElementById ('processing'). innerHTML = msg;
}
</Script>
</Head>
<Body>
<Div style = "text-align: center">
<Div id = "processing"> </div>
<Form action = "upload. php tutorial" method = "post" enctype = "multipart/form-data" target = "form-target" onsubmit = "startUpload ();">
<Input type = "hidden" name = "MAX_FILE_SIZE" value = "1000000"/>
<Input type = "file" name = "myfile"/>
<Input type = "submit" name = "sub" value = "upload"/>
</Form>
<Iframe style = "width: 0; height: 0; border: 0;" name = "form-target"> </iframe>
</Div>
</Body>
</Html>
Php code
<? Php
Sleep (2 );
$ FileTypes = array ('jpg ', 'png', 'gif', 'bmp ');
$ Result = null;
$ UploadDir = './upfiles ';
$ MaxSize = 1 * pow (2, 20 );
If ($ _ SERVER ['request _ method'] = 'post' & isset ($ _ POST ['sub ']) {
$ Myfile = $ _ FILES ['myfile'];
$ MyfileType = substr ($ myfile ['name'], strrpos ($ myfile ['name'], ".") + 1 );
If ($ myfile ['SIZE']> $ maxSize ){
$ Result = 1;
} Else if (! In_array ($ myfileType, $ fileTypes )){
$ Result = 2;
} Elseif (is_uploaded_file ($ myfile ['tmp _ name']) {
$ ToFile = $ uploadDir. '/'. $ myfile ['name'];
If (@ move_uploaded_file ($ myfile ['tmp _ name'], $ toFile )){
$ Result = 0;
} Else {
$ Result =-1;
}
} Else {
$ Result = 1;
}
}
?>
<Script type = "text/javascript">
Window. top. window. stopUpload (<? Php echo $ result;?> );
</Script>