Php file Upload move_uploaded_file function

Source: Internet
Author: User
Tags http post php file php file upload

Move_uploaded_file (file, newloc) parameter description
File is required. Specifies the file to be moved.
Newloc is required. Specifies the new location of the file

The code is as follows: Copy code

<! Doctype html public "-// w3c // dtd xhtml 1.0 transitional // en" "">
<Html xmlns = "">
<Meta http-equiv = "content-type" content = "text/html; charset = gb2312"/>
<Title> php file upload function </title>


<Form enctype = "multipart/form-data" action = "upload. php" method = "post">
<Input type = "hidden" name = "max_file_size" value = "30000"/>
<Input name = "userfile" type = "file"/>
<Input type = "submit" value = "send file"/>

The code is as follows: Copy code
If ($ _ post)
If (uploadfile ("userfile "))
Echo 'file uploaded successfully ';
Echo 'file Upload failed ';
// The parameter $ file is the name of the foreground file control;
Function uploadfile ($ file)
$ Uploaddir = $ _ server ['document _ root']. '/ /';
$ File_name = $ uploaddir. rand (1,000000). ".". fileextend ($ _ files [$ file] ['name']);
If (move_uploaded_file ($ _ files [$ file] ['tmp _ name'], $ file_name ))
Return true;
Return false;

Tips and comments
Note: This function is only used for files uploaded through http post.

Note: If the target file already exists, it will be overwritten.

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: 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.