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.