Upload code for php beginners (1/3)

Source: Internet
Author: User
Tags file upload html form php tutorial

Create a file upload form
It is very useful to allow users to upload files from forms.

 

Create a file upload form
It is very useful to allow users to upload files from forms.
See the following html form for uploading files:
Copy the code as follows:

<Html>
<Body>
<Form action = "upload_file.php tutorial" method = "post"
Enctype = "multipart/form-data">
<Label for = "file"> filename: </label>
<Input type = "file" name = "file" id = "file"/>
<Br/>
<Input type = "submit" name = "submit" value = "submit"/>
</Form>
</Body>
</Html>

Pay attention to the following information about this form:
<Form> The enctype attribute of a tag specifies the content type to be used when submitting a form. When a form requires binary data, such as file content, use multipart/form-data ".
<Input> the type = "file" attribute of the tag specifies that the input should be processed as a file. For example, when previewing in a browser, a browser button is displayed next to the input box.
Note: allowing users to upload files is a huge security risk. Only trusted users are allowed to upload files.
Create Upload script
The "upload_file.php" file contains the code for uploading files:
Copy the code as follows:

<? Php
If ($ _ files ["file"] ["error"]> 0)
{
Echo "error:". $ _ files ["file"] ["error"]. "<br/> ";
}
Else
{
Echo "upload:". $ _ files ["file"] ["name"]. "<br/> ";
Echo "type:". $ _ files ["file"] ["type"]. "<br/> ";
Echo "size:". ($ _ files ["file"] ["size"]/1024). "kb <br/> ";
Echo "stored in:". $ _ files ["file"] ["tmp_name"];
}
?>

 

Homepage 1 2 3 Last page

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.