PHP File Upload example

Source: Internet
Author: User
Tags php file upload
I have been busy with the transition from ASP to PhP recently. PHP is a lot easier to learn! Here is an example of File Upload. By the way, you can write down the learning logs. for complex operations, learn more...
Index. php program code on the form page <form method = "Post" Action = "Upload. php" enctype = "multipart/form-Data">
File: <input type = "file" name = "userfile"/>
<Input type = "Submit" value = "Upload File"/>
</Form>

Do not forget this sentence. enctype = "multipart/form-Data"
Upload page upload. asp. below isCode, Just two or three program codes <? PHP
If (move_uploaded_file ($ _ FILES ['userfile'] ['tmp _ name'], getcwd (). "\\". $ _ FILES ['userfile'] ['name'])
Echo "OK! ";
Else
Echo "failed! ";
?>

Get the uploaded file through the $ _ FILES array. Here, the userfile corresponds to the name attribute of the form, and $ _ FILES ['userfile'] ['name'] gets the name of the uploaded file, $ _ FILES ['userfile'] ['tmp _ name'] is a temporary file name for uploading files stored on the server. The getcwd () function obtains the directory of the current file, move_uploaded_file: Move the uploaded file to the specified position. The returned value is a Boolean value. If the operation succeeds, the file is uploaded successfully.

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.