First:
Php Section
Copy codeThe 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 '$ 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
}
?>