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