日期:2014-05-18  浏览次数:20461 次

用AJAX上传图片,在本地测试可以,上传服务器不行,请指点
代码
System.Drawing.Image   img   =   System.Drawing.Image.FromFile(fileInfo);
System.IO.MemoryStream   ms   =   new   System.IO.MemoryStream();
//取得文件的扩展名,保存文件格式
int   j=fileInfo.LastIndexOf( "\\ ");
int   i=fileInfo.LastIndexOf( ". ");
string   fileName=fileInfo.Substring(j+1,i-j);
string   extName=fileInfo.Substring(i+1);
switch(extName.ToUpper())
{
case   "GIF ":
img.Save(ms,   System.Drawing.Imaging.ImageFormat.Gif);
break;
default   :
img.Save(ms,System.Drawing.Imaging.ImageFormat.Jpeg);
break;
}
string   newname=DateTime.Now.Year.ToString()+DateTime.Now.Month.ToString()+DateTime.Now.Day.ToString()+DateTime.Now.Hour.ToString()+DateTime.Now.Minute.ToString()+DateTime.Now.Second.ToString();
byte[]   by   =   ms.ToArray();
string   savePath   =   Server.MapPath( "images\\product ");
FileStream   fileStream   =   null;
try
{
fileStream   =   new   FileStream(savePath.Replace( "\\ajax ", " ")   +   "c:\\ "   +   newname+ ". "+extName,   FileMode.Create,   FileAccess.Write);
//fileStream   =   new   FileStream(   "c:\\up\\ "   +   newname+ ". "+extName,   FileMode.Create,   FileAccess.Write);
//write   the   file
fileStream.Write(by,   0,   by.Length);
fileStream.Flush();//clear   the   buffer,write   the   data   to   the   hard   disk

}
catch(Exception   ex)
{
string   s=ex.ToString();
throw;
}
finally
{
fileStream.Close();
}

------解决方案--------------------
就看到你上传文件的代码,没看到ajax,不知道你怎么处理的,是不是用了微软的ajax框架?
------解决方案--------------------
你的Ajax.dll上传文件可以用了吗?我试你的方法,也只能本地测试成功.我想是因为你System.Drawing.Image img = System.Drawing.Image.FromFile(fileInfo);的原因吧fileInfo是服务器上的图片路径才对.而本地测试时,fileInfo又是本地又是服务器上,所以能成功.而远程测试的话,服务器根本不存在fileInfo,所以就不行了