[Code] Simple PHP Image Upload implementation

Source: Internet
Author: User

The following program uses the move_uploaded_file function to upload images to the program directory, with the prefix temp.

The following is a code snippet:
<Html>
<Head>
<Title> php (as the mainstream development language) allows you to upload images to www.cncms.com.cn. </title>
</Head>
<Body>
<? Php (as the mainstream development language)
If ($ _ GET ['action'] = 'upfile ')
{
$ Target_path = 'temp _ '. $ _ FILES ['photo'] ['name'];
Echo 'uploaded temporary file: '. $ _ FILES ['photo'] ['tmp _ name'].' <br/> ';
Echo 'destination File Uploaded: '. $ target_path.' <br/> ';
Echo $ _ SERVER ["SCRIPT_FILENAME"]. '<br/> ';
Echo $ _ SERVER ["OS"]. '<br/> ';
// Test function: move_uploaded_file
// You can also use the function: copy
Move_uploaded_file ($ _ FILES ['photo '] ['tmp _ name'], $ target_path );
Echo "Upload result :";
If (file_exists ($ target_path )){
If ($ _ SERVER ["OS"]! = "Windows_NT "){
@ Chmod ($ target_path, 0604 );
}
Echo '<font color = "green"> Succeed! </Font> <br/> <a href = "http ://'. $ _ SERVER ["SERVER_NAME"]. "/". $ target_path. '"> ';
} Else {
Echo '<font color = "red"> Failed! </Font> ';
}
Exit;
}
?>
<H1> Registration <Form action = "upload. php (as the mainstream development language )? Action = upfile "method =" post "name =" UForm "enctype =" multipart/form-data ">
<Fieldset>
<Legend> Your information </legend>
<Ul>
<Li> Your Phot <input type = "file" name = "photo"> </li>
</Ul>
</Fieldset>
<Button type = "submit"> upload </button>
</Form>
</Body>
</Html>

Never-ending technical exchanges

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.