文件上载在本地,但不在服务器中 [英] File Upload is working in local, but not in server

查看:84
本文介绍了文件上载在本地,但不在服务器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在网站上传用户图片。这里我使用FileUpload控件上传图片。



我的代码是这样的



I'm trying to upload user image on website. Here I'm using FileUpload control to upload image.

My Code is like this

string fileName = string.Empty;
if (fuFranchiseImage.HasFile == true)
{
    fileName = DateTime.Now.ToString("MM-dd-yyyy_HHmmss");
    string fileExtension = System.IO.Path.GetExtension(this.fuFranchiseImage.FileName).ToString();
    fileName = fileName + fileExtension;
    string filePath = Server.MapPath(@"~\images\" + fileName);
    fuFranchiseImage.SaveAs(filePath);
}

Here i'm trying to save images into images folder in the application, and in SQL Server i just save file name.

When I try to upload in server its getting error like this

Access to the path 'D:\Hosting\12374540\html\report\images\04-10-2014_000650.jpg' is denied.


Please could anyone help me to solve this problem

推荐答案

代码中没有问题。您必须为服务器上的images目录设置访问权限(Permission)。目前您无权在服务器上保存图像。
There is no issue in code. You have to set access rights(Permission) for images directory on server. Currently you don't have access to save image on server.


检查您的文件夹权限:您可能需要对所有用户的写访问权。
Check your folder permissions: you probably need write access to all users.


I认为你的

字符串错误是错误的.Path = Server.MapPath(@〜\ images. ++ fileName);

我认为你应该松开〜

我写道:

string filePath = Server.MapPath(@\ images \+ fileName);



string filePath = Server.MapPath(〜\ images \+ fileName);
I think it's wrong with your
string filePath = Server.MapPath(@"~\images\" + fileName);
I think you shall loose the ~
I write:
string filePath = Server.MapPath(@"\images\" + fileName);
or
string filePath = Server.MapPath("~\images\" + fileName);


这篇关于文件上载在本地,但不在服务器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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