图像未保存到Web服务器上的文件夹但保存在localhost中 [英] Images not saving to the folder on the webserver but saving in localhost

查看:101
本文介绍了图像未保存到Web服务器上的文件夹但保存在localhost中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试使用fileupload控件保存在localhost机器中时将图像保存在文件夹中,但是从其他计算机访问此URL时它无法显示运行时错误。

如果我运行此URL网络服务器,然后这工作,但从外面不工作,我给了IUser,本地服务,网络服务等的全部权利...



以下是我的代码


When trying to save the Image in the folder using fileupload control saving in localhost machine,but accessing this URL from other machines it is not working showing Run time error.
if i run this URL from webserver then this works,but from outside not working, i gave full rights to IUser,Local Service,Network Service etc...

Below is my code

if (FileUploadSignature.HasFile)
        {
            string ImgExt = System.IO.Path.GetExtension(FileUploadSignature.PostedFile.FileName).ToUpper();
            if (ImgExt == ".PNG" || ImgExt == ".BMP" || ImgExt == ".GIF" || ImgExt == ".JPG" || ImgExt == ".JPEG")
            {
                if (System.IO.File.Exists(Server.MapPath(@"~\Signature\" + txtEmployeeID.Value.Trim() + ".Jpeg")))
                {
                    System.IO.File.Delete(Server.MapPath(@"~\Signature\" + txtEmployeeID.Value.Trim() + ".Jpeg"));
                }

                System.Drawing.Image image = System.Drawing.Image.FromFile(FileUploadSignature.PostedFile.FileName);
                int thumbWidth = image.Width;
                if (thumbWidth > 100)
                {
                    thumbWidth = 100;
                }
                else
                {
                    thumbWidth = image.Width;
                }
                int srcWidth = image.Width;
                int srcHeight = image.Height;
                Decimal sizeRatio = ((Decimal)srcHeight / srcWidth);
                int thumbHeight = Decimal.ToInt32(sizeRatio * thumbWidth);
                Bitmap bmp = new Bitmap(thumbWidth, thumbHeight);
                System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bmp);
                gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
                System.Drawing.Rectangle rectDestination = new System.Drawing.Rectangle(0, 0, thumbWidth, thumbHeight);
                gr.DrawImage(image, rectDestination, 0, 0, srcWidth, srcHeight, GraphicsUnit.Pixel);
                bmp.Save(Server.MapPath(@"~\Signature\"+txtEmployeeID.Value.Trim()+".Jpeg"), System.Drawing.Imaging.ImageFormat.Jpeg);
                bmp.Dispose();
                ShowMessage("Saved Sucessfully");
            }
            else
            {
                ShowMessage("Invalid Picture Format/Type");
                return;
            }
        }
        else
        {
            ShowMessage("Please select the image then click save");
            return;
        }

推荐答案

这篇关于图像未保存到Web服务器上的文件夹但保存在localhost中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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