Php image file Upload instance code

Source: Internet
Author: User
Tags error code file upload php tutorial
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.