<! Doctype html public "-// w3c // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <Html xmlns = "http://www.w3.org/1999/xhtml"> <Head> <Meta http-equiv = "content-type" content = "text/html; charset = gb2312"/> <Title> ajax file Upload </title> <Style type = "text/css tutorial"> # F1_upload_process {display: none ;} </Style> <Script language = "webpage effect" type = "text/javascript"> <! -- Function $ (id) { Return document. getelementbyid (id ); } Function startupload (){ If ($ ('myfile'). value = '') { Alert ('select the image to upload! '); Return false; } Var array = $ ('myfile'). value. split ('.'); Var ext = array [1]. tolowercase (); If (ext = "gif" | ext = "jpg" | ext = "png ") { $('F1 _ upload_process '). style. display = 'block '; $('F1 _ upload_form '). style. display = 'block '; Return true; } Else { Alert ('only images in gif. jpg png format can be uploaded! '); Return false; } } Function stopupload (success, pic ){ Var result = ''; If (success = 1 ){ Result = ' '; $ ('Logo '). value = pic; } Else { Result = '<span class = "emsg"> failed to upload logo images. Please contact the developer! </Span> <br/> '; } $('F1 _ upload_process '). style. display = 'none '; $('F1 _ upload_form '). innerhtml = result + '<br/> <label> <input name = "myfile" type = "file" size = "30"/> </label> <input type = "submit" name = "submitbtn" class = "sbtn" value = "upload image"/> </label> '; $('F1 _ upload_form '). style. display = 'block '; Return true; } // --> </Script> </Head> <Body> <Form action = "upload. php Tutorial "method =" post "enctype =" multipart/form-data "target =" upload_target "onsubmit =" javascript: return startupload (); "> <Span id = "f1_upload_process"> </span> <Span id = "f1_upload_form" align = "center"> <Input name = "myfile" type = "file" id = "myfile" size = "30"/> <Input type = "submit" name = "submitbtn" class = "sbtn" value = "upload image"/> </Span> <Iframe id = "upload_target" name = "upload_target" src = "#" style = "width: 0; height: 0; border: 0px solid # fff; "> </iframe> (You can upload gif, jpg, and png files) </Form> </Body> </Html> |