Php file Upload move_uploaded_file function

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

Syntax
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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.111cn.net/1999/xhtml">
<Head>
<Meta http-equiv = "content-type" content = "text/html; charset = gb2312"/>
<Title> php file upload function </title>
</Head>

<Body>

<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"/>
</Form>
</Body>
</Html>

The code is as follows: Copy code
<?
If ($ _ post)
{
If (uploadfile ("userfile "))
 {
Echo 'file uploaded successfully ';
 }
Else
 {
Echo 'file Upload failed ';
 }
}
// The parameter $ file is the name of the foreground file control;
Function uploadfile ($ file)
{
$ Uploaddir = $ _ server ['document _ root']. '/www.111cn.net/uploadfile /';
$ File_name = $ uploaddir. rand (1,000000). ".". fileextend ($ _ files [$ file] ['name']);
If (move_uploaded_file ($ _ files [$ file] ['tmp _ name'], $ file_name ))
    {
Return true;
    }
Else
    {
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.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.