Provides a simple and practical php Image File Upload instance code
Php tutorial Image File Upload instance code
<Html xmlns = "http://www.bkjia.com/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>
<?
If ($ _ post)
{
If ($ _ files ['file'])
{
$ Filename = $ _ files ['file'] ['type'];
$ Newname require 'php100.com.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.bkjia.com/phper/24/da78cda75379943ff126f6af13cf5aa9.htm
Strtolower instance address
Http://www.bkjia.com/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 to indicate the source of http://www.bkjia.com/phper/php.html