Asp.net allows you to upload images to display absolute local path images. In fact, it is better to use <DIV> </DIV> to display images! Using js to achieve proportional compression of images makes the image as clear as it is!
Paste the code below
The page code is mainly JS
- View plaincopy to clipboardprint?
- <Head runat = "server">
- <Title> No title page </title>
- <Mce: script language = "javascript" type = "text/javascript"> <! --
- Function Imagesrc ()
- {
- Document. getElementById ("image"). src = document. all. FileUpload1.value;
- }
- // --> </Mce: script>
- </Head>
- <Body>
- <Form id = "form1" runat = "server">
- <Div>
- <Asp: FileUpload ID = "FileUpload1" runat = "server" onchange = "Imagesrc ()"/>
- <Br/>
- <Asp: Button ID = "btnPost" runat = "server"
- Text = "Upload" OnClick = "btnPost_Click"/> </div>
- </Form>
- </Body>
- <Head runat = "server">
- <Title> No title page </title>
- <Mce: script language = "javascript" type = "text/javascript"> <! --
- Function Imagesrc ()
- {
- Document. getElementById ("image"). src = document. all. FileUpload1.value;
- }
- // --> </Mce: script>
- </Head>
- <Body>
- <Form id = "form1" runat = "server">
- <Div>
- <Asp: FileUpload ID = "FileUpload1" runat = "server" onchange = "Imagesrc ()"/>
- <Br/>
- <Asp: Button ID = "btnPost" runat = "server"
- Text = "Upload" OnClick = "btnPost_Click"/> </div>
- </Form>
- </Body>
- Defualt. aspx. cs code
- View plaincopy to clipboardprint?
- Protected void btnPost_Click (object sender, EventArgs e)
- {
- String PostName = Server. MapPath ("Image ");
- String fileName = FileUpload1.FileName;
- // Whether the file is included
- If (FileUpload1.HasFile)
- {
- FileUpload1.SaveAs (PostName "/" fileName );
- }
- }