PHP-----Uploading files

Source: Internet
Author: User

File Upload

How do I upload a file??

-----------------------------------------------Main Page-----------------------------------------------

<title> Untitled Document </title>

<body>

<form action= "chuli.php" method= "POST" enctype= "Multipart/form-data" ><!-- If this form is used to upload a file, an additional attribute is required: enctype= the type of the "Multipart/form-data" commit data, which is a file data --

<input type= "file"/><!-- This tag can be used to select files --

<!--file Upload is given this tag to achieve--

<!--through this tab to finish the file, to put this file can be submitted to another page to achieve-

<!--<input type= "file"/> He is a form element. As long as it is a form element, it can be submitted. Submit it to another page to process--

<!-- Upload file is based on the form of the submission function, to achieve . -

<input type= "Submit" value= "upload"/><!-- upload file needs to be completed with form submission--

<!--Select File is the selected client's file, which computer uses the computer to select the file. When you click Upload submit to another page called Processing page, processing page only PHP code, he just contains PHP code to be processed by the server's PHP, so it is equivalent to from the client to take the file to the service side processing so that you can complete a file, from the client to the service side of the process. -

</form>

</body>

----------------------------------------------Process the page----------------------------------------------

<?php

a file was submitted, and the Name= "file, the document selection form name is called" file,

In the processing of the page how to transfer the value of the

If you are submitting a file for upload , you need to get it from the $_files array .

Var_dump ($_files);

The results displayed:

is a two-dimensional array

file represents the name value of the submitted form , and an array containing the information for uploading the file.

Error error message
Size of the upload file int 2786 This is in bytes
It is present in the $_files array.
var_dump ($_files["file"]);//can fetch the uploaded information

Hit the processing page, this file temporarily exists the server, not on the client, temporary existence of the F:\PHP1\wamp\tmp\ Php8c5c.tmp this position, now to the file how to complete a file upload, is to save the temporary file, specify a directory to save (in the directory), so that the upload completed.
However,  in the upload of the past, the need for those processing it?? 
First,  not all files can be uploaded, to control the type of upload files ,
Second, to control, upload the file size. can not allow users to upload too large files, because this space is limited, if each user uploads large files, the space is immediately full, full of it.
If you upload a picture, it's dozens of K. will be used: ' size ' = + int 4173
To hide these conditions, you need this directory when saving temporary files : ' tmp_name ' = = String ' F:\PHP1\wamp\tmp\php73ED.tmp ' need this directory to find this file, There will be another directory after the file is found
To store the file name, name also needs ' name ' = = String ' code picture. png '

PHP-----Uploading files

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.