First:
PHP Section
CopyCode The Code is as follows: <? PHP
If ($ _ FILES ['file'] ['error']> 0 ){
Echo '! Problem :';
Switch ($ _ FILES ['file'] ['error'])
{
Case 1: Echo 'file size exceeds server limited ';
Break;
Case 2: Echo 'the file is too large! ';
Break;
Case 3: ECHO: only part of the file is loaded! ';
Break;
Case 4: Echo 'file loading failed! ';
Break;
}
Exit;
}
If ($ _ FILES ['file'] ['SIZE']> 1000000 ){
Echo 'The file is too large! ';
Exit;
}
If ($ _ FILES ['file'] ['type']! = 'Image/JPEG '& $ _ FILES ['file'] ['type']! = 'Image/gif '){
Echo: The file is not jpg or GIF! ';
Exit;
}
$ Today = date ("ymdhis ");
$ Filetype = $ _ FILES ['file'] ['type'];
If ($ filetype = 'image/JPEG '){
$ Type = '.jpg ';
}
If ($ filetype = 'image/gif '){
$ Type = '.gif ';
}
$ Upfile = 'upfile/'. $ today. $ type;
If (is_uploaded_file ($ _ FILES ['file'] ['tmp _ name'])
{
If (! Move_uploaded_file ($ _ FILES ['file'] ['tmp _ name'], $ upfile ))
{
Echo 'failed to move the file! ';
Exit;
}
}
Else
{
Echo 'problem! ';
Exit;
}
Echo 'Echo 'file size: '. $ _ FILES ['file'] ['SIZE']. 'byte'. '<br> ';
Echo 'file path: '. $ upfile;
Echo '<HR with = "100%"/>'. '<p> ';
$ Dirr = 'upfile /';
$ Dir = opendir ($ dirr );
Echo $ dirr. '-- listing: <ul> ';
While ($ file = readdir ($ DIR )){
Echo "<li> $ file </LI> ";
}
Echo '</ul> ';
Closedir ($ DIR );
?>
Second:Copy codeThe Code is as follows: <? PHP
If (empty ($ _ Get [Submit])
{
?>
<Form enctype = "multipart/form-Data" Action = "<? PHP $ _ server ['php _ Self ']?>? Submit = 1 "method =" Post ">
Send this file: <input name = "FILENAME" type = "file">
<Input type = "Submit" value = "Confirm upload">
</Form>
<? PHP
} Else {
$ Path = "uploadfiles/"; // upload path
// Echo $ _ FILES ["FILENAME"] ["type"];
If (! File_exists ($ PATH ))
{
// Check whether the folder exists. If not, create the folder and grant the highest permission.
Mkdir ("$ path", 0700 );
} // End if
// File format that can be uploaded
$ TP = array ("image/GIF", "image/pjpeg", "image/PNG ");
// Check whether the uploaded file is of the allowed upload type
If (! In_array ($ _ FILES ["FILENAME"] ["type"], $ TP ))
{
Echo "invalid format ";
Exit;
} // End if
If ($ _ FILES ["FILENAME"] ["name"])
{
$ File1 = $ _ FILES ["FILENAME"] ["name"];
$ File2 = $ path. Time (). $ file1;
$ Flag = 1;
} // End if
If ($ flag) $ result = move_uploaded_file ($ _ FILES ["FILENAME"] ["tmp_name"], $ file2 );
// Note that the first parameter passed to move_uploaded_file is the temporary file uploaded to the server.
If ($ result)
{
// Echo "Upload successful! ". $ File2;
Echo "<script language = 'javascript '> ";
Echo "alert (\" uploaded successfully! \");";
Echo "location = 'add _ AAA. php? Pname = $ file2 '";
Echo "</SCRIPT> ";
} // End if
}
?>