The code is as follows: |
Copy code |
<Html xmlns = "http://www.111cn.net/1999/xhtml"> <Head> <Meta http-equiv = "content-type" content = "text/html; charset = gb2312"/> <Title> php Tutorial image file Upload instance code </title> </Head> <Body> <Form action = "" method = "post" enctype = "multipart/form-data" name = "form1" id = "form1"> <Label for = "filefield"> </label> <Input type = "file" name = "file" id = "filefield"/> <Input type = "submit" name = "button" id = "button" value = "file upload"/> </Form> </Body> </Html> |
<?
The code is as follows: |
Copy code |
If ($ _ post) { If ($ _ files ['file']) { $ Filename = $ _ files ['file'] ['type']; $ Newname require '111cn.net.gif '; If (strtolower ($ filename) = 'image/GIF ') { If (move_uploaded_file ($ _ files ['file'] ['tmp _ name'], $ newname )) { // $ Ext = getimagesize ($ newname ); // Print_r ($ ext ); Echo 'image uploaded successfully '; } Else { Die ('image Upload failed! '); } } Else { Exit ('The program only allows uploading GIF image '); } } } |
/*
Move_uploaded_file syntax reference address
Http://www.111cn.net/phper/24/da78cda75379943ff126f6af13cf5aa9.htm
Strtolower instance address
Http://www.111cn.net/phper/21/805cd7d41d20a10b71b35e1a8f2b8596.htm
$ _ Files
$ _ Files [''myfile'] [''Name''] original name of the client file.
$ _ Files [''myfile'] [''type''] mime type of the file. The file must be supported by the browser, for example, "image/gif ".
$ _ Files ['myfile'] ['size'] size of the uploaded file, in bytes.
$ _ Files ['myfile'] [''tmp _ name''] temporary file name stored on the server after the file is uploaded, which is generally the default file name. It can be specified in upload_tmp_dir of php. ini, but the putenv () function setting does not work.
$ _ Files [''myfile'] [''error''] error code related to the file upload. [''Error''] is added in php 4.2.0.
*/
?>
This site original tutorials reprinted indicate the source of http://www.111cn.nethttp: // www.111cn.net/phper/php.html