GDI 中发生一般错误,可能是 server.mappath 问题

发布于 2024-09-11 01:48:28 字数 1069 浏览 2 评论 0原文

我已经将问题范围缩小到了这段代码,我在其中调整上传图像的大小并保存它。这在我的本地计算机上运行良好,但是当我在服务器上运行该站点时,我收到来自“thumbnail.Save”调用的通用 GDI+ 错误。

if(fup_displayPicUpload.HasFile)
            {
                string imageDir = Server.MapPath("./images/");

                if (!Directory.Exists(imageDir + username))
                {
                    Directory.CreateDirectory(imageDir + username);
                    lbl_profileMessage.ForeColor = Color.Yellow;
                    lbl_profileMessage.Text = "Created User Folder";
                }
                String userFolder = imageDir + username + "/";

                using (System.Drawing.Image originalPhoto = new Bitmap(new MemoryStream(fup_displayPicUpload.FileBytes)))
                {
                    System.Drawing.Image thumbnail = originalPhoto.GetThumbnailImage(300, 300, Abort, IntPtr.Zero);
                    thumbnail.Save(userFolder + "displaypicture.jpg", ImageFormat.Jpeg);
                }

                displayPictureUrl = "/images/" + username + "/displaypicture.jpg";

            }

I've narrowed down the issue I'm having to this block of code, where I am resizing an uploaded image and saving it. This works fine on my local machine, but when I run the site on the server, I get a generic GDI+ error that's coming from the "thumbnail.Save" call.

if(fup_displayPicUpload.HasFile)
            {
                string imageDir = Server.MapPath("./images/");

                if (!Directory.Exists(imageDir + username))
                {
                    Directory.CreateDirectory(imageDir + username);
                    lbl_profileMessage.ForeColor = Color.Yellow;
                    lbl_profileMessage.Text = "Created User Folder";
                }
                String userFolder = imageDir + username + "/";

                using (System.Drawing.Image originalPhoto = new Bitmap(new MemoryStream(fup_displayPicUpload.FileBytes)))
                {
                    System.Drawing.Image thumbnail = originalPhoto.GetThumbnailImage(300, 300, Abort, IntPtr.Zero);
                    thumbnail.Save(userFolder + "displaypicture.jpg", ImageFormat.Jpeg);
                }

                displayPictureUrl = "/images/" + username + "/displaypicture.jpg";

            }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

歌入人心 2024-09-18 01:48:28

最常见的原因是您尝试保存图像的目录出现访问被拒绝错误。确保运行应用程序的用户具有对目标目录的写访问权限。

The most common cause of this is an access denied error to the directory that you are trying to save the image to. Make sure that the user that the application is running as has write access to the destination directory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文