求助:文件上传问题!未能找到文件“C:\Documents and Settings\Administrator\桌面\221.jpg”。
在本机测试没有问题放在服务器的然后就报错
未能找到文件“C:\Documents and Settings\Administrator\桌面\221.jpg”。
--------------------编程问答-------------------- 在服务器上报“未能找到文件“C:\Documents and Settings\Administrator\桌面\221.jpg”。”,你服务器这个地址有这个图片吗? --------------------编程问答-------------------- --------------------编程问答-------------------- 哈哈,抄来抄去,把对的抄成错的了!太牛了!
String fileTypes = "gif,jpg,jpeg,png,bmp";
//最大文件大小
int imgMaxSize = Convert.ToInt32(MaxSize) * 1024 * 1024;
HttpPostedFile imgFile = FuImg.PostedFile;
if (imgFile == null || FuImg.FileName == "")
{
Alert("请选择文件。");
return "";
}
String dirPath = SavePath;
string saveUrl = SaveUrl;
if (!Directory.Exists(dirPath))
{
Alert("上传目录不存在。");
return "";
}
String fileName = imgFile.FileName;
String fileExt = Path.GetExtension(fileName).ToLower();
ArrayList fileTypeList = ArrayList.Adapter(fileTypes.Split(','));
if (imgFile.InputStream == null || imgFile.InputStream.Length > imgMaxSize)
{
Alert("上传文件大小超过限制。");
return "";
}
if (String.IsNullOrEmpty(fileExt) || Array.IndexOf(fileTypes.Split(','), fileExt.Substring(1).ToLower()) == -1)
{
Alert("上传文件扩展名是不允许的扩展名。");
return "";
}
//验证文件格式
if (!IsAllowedExtension(imgFile, fileTypes))
{
Alert("图片格式不正确。");
return "";
}
String ymd = DateTime.Now.ToString("yyyyMMdd", DateTimeFormatInfo.InvariantInfo);
dirPath += ymd + "/";
saveUrl = SaveUrl + ymd + "/";
//判断目录是否存在
if (!Directory.Exists(dirPath))
{
//创建目录
Directory.CreateDirectory(dirPath);
}
String newFileName = Guid.NewGuid().ToString() + fileExt;//图片名字
String filePath = dirPath + newFileName;
imgFile.SaveAs(filePath);
String fileUrl = SaveUrl + newFileName;
ImageUrl = Img.ImageUrl = saveUrl + newFileName;
//ImageUrl = saveUrl + newFileName;
txtedit.Text = "";
--------------------编程问答-------------------- 把图片放其他盘里试试,你那个saveurl是服务器保存路径吗? --------------------编程问答--------------------
我发现了确实是这里的问题。但是有没有方法可以做服务器端的呢?我想了解下。 --------------------编程问答--------------------
可以做的。我写过 --------------------编程问答--------------------
补充:.NET技术 , ASP.NET