如何显示服务器文件夹中的图像 [英] How to display an image from a server folder

查看:120
本文介绍了如何显示服务器文件夹中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我将客户端的图像上传到服务器文件夹,然后将该链接保存到数据库.使用FileUpload加载图像,然后将其保存到特定的服务器文件夹中,并将路径保存到数据库中.但是上传照片时,图像无法显示在图像控件中.我该如何解决?

这是我的代码:

 s = browser.FileName.ToString();
//  photoid.ImageUrl = s; 
photoid1.Src = s;
如果((( .browser.PostedFile!= >空)&&( .browser.PostedFile.ContentLength >   0 ))
{
     FileName = System.IO.Path.GetFileName(browser.PostedFile.FileName);
     //  SaveLocation = Server.MapPath("PhotoId")+"\\" + FileName; 
    SaveLocation = "  + FileName;
    
     .browser.PostedFile.SaveAs(SaveLocation);
    //  photoid.ImageUrl = SaveLocation;//this.browser.PostedFile.FileName; 
    //  photoid1.Src = SaveLocation; 
}
    btnloadimage.Text = " ;
    如果(s!= " )
    {
        browser.Visible =  false ;
        btnloadimage.Text = " ;
    } 

解决方案

您是否检查了目标目录是否具有足够的访问权限,并且整个目录树的web.config都将允许它?

您应该具有一个可以从客户端访问图像的文件夹,或者您已经创建了一个图像处理程序以将图像的内容直接写入响应中.

将图像放在虚拟目录中的任何文件夹下.您的客户可以访问它.

看看,如果您的src ="/images/x.jpg"
它访问已发布文件夹下的文件夹图像.

如果您写
src ="D:\ docs \ x.jpg"

对客户没有意义.

:cool:

还是有困惑,让我知道.


Hello all,

I m uploading the client''s image to a server folder and I save that link to the database. The image is loaded using FileUpload and saved to a specific server folder and the path is saved to the database. But the image can not be displayed in an image control while uploading the photo. How can I fix this?

Here is my code:

s= browser.FileName.ToString() ;
//photoid.ImageUrl = s;
photoid1.Src = s;
if ((this.browser.PostedFile != null) && (this.browser.PostedFile.ContentLength > 0))
{
     FileName = System.IO.Path.GetFileName(browser.PostedFile.FileName);
     //SaveLocation = Server.MapPath("PhotoId")+"\\" + FileName;
    SaveLocation ="D:\\Sagar\\Bulk Transportation\\Bulk Transportation\\PhotoId\\"+ FileName;
    
    this.browser.PostedFile.SaveAs(SaveLocation);
    //photoid.ImageUrl = SaveLocation;//this.browser.PostedFile.FileName;
    //photoid1.Src = SaveLocation;
}
    btnloadimage.Text = "Save Image";
    if (s != "")
    {
        browser.Visible = false;
        btnloadimage.Text = "Load Photo";
    }

解决方案

Have you checked that the destination directory has sufficient access rights and that web.config for the entire directory tree will allow it?


You should have either the folder where you place the images accessible from the client, or you have created one Image Handler to write the contents of the image directly in the response.

Place the images just under any folder within your virtual directory. Your client can access it.

See, if your src = "/images/x.jpg"
it accesses a folder images just under your published folder.

If you write
src="D:\docs\x.jpg"

No meaning to the client.

:cool:

Still have confusion, let me know.


这篇关于如何显示服务器文件夹中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆