同样的一段程序,为什么我的本地可以用,上传到服务器就不能用了?
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
public partial class FS_OA_webs_UploadPic : System.Web.UI.Page
{
private int newwidth;
private int newheight;
private System.Drawing.Bitmap b;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
UploadPan.Visible = true;
UploadedPan.Visible = false;
}
}
protected void UploadBtn_Click(object sender, System.EventArgs e)
{
if(Page.IsValid)
{
if(UploadFile.PostedFile.ContentLength/1024> 2024)
{
Response.Write( " <script language= 'javascript '> alert( '上传的图片过大! '); </script> ");
}
else if(UploadFile.PostedFile.ContentType.ToLower().ToString().Substring(0,5)!= "image ")
{
Response.Write( " <script language= 'javascript '> alert( '上传的文件的类型不正确! '); </script> ");
}
else
{
string num=UploadFile.PostedFile.FileName;
int i=num.LastIndexOf( '. ');
string newtype=num.Substring(i);
string newname=System.DateTime.Now.Year.ToString().Trim() + System.DateTime.Now.Month.ToString().Trim()
+ System.DateTime.Now.Day.ToString().Trim() + System.DateTime.Now.Hour.ToString().Trim() + System.DateTime.Now.Minute.ToString().Trim()
+ System.DateTime.Now.Second.ToString().Trim() + UploadFile.PostedFile.ContentLength;
b=new System.Drawing.Bitmap(num);
if(b.Width> 100)
{
newwidth=100;
newheight=(b.Height*newwidth)/b.Width;
System.Drawing.Image img=b.GetThumbnailImage(newwidth,newheight,null,IntPtr.Zero);
img.Save(Server.MapPath( "images\\SmallImage\\ "+newname+newtype),System.Drawing.Imaging.ImageFormat.Jpeg);
}
else
{
UploadFile.PostedFile.SaveAs(Server.MapPath( "images\\SmallImage\\ " + newname + newtype));
}
if(b.Width> 600)
{
newwidth=600;
newheight=(b.Height*newwidth)/b.Width;
System.Drawing.Image img=b.GetThumbnailImage(newwidth,newheight,null,IntPtr.Zero);
img.Save(Server.MapPath( "images\\BigImage\\ " + newname + newtype), System.Drawing.Imaging.ImageFormat.Jpeg);
}
else
{
UploadFile.PostedFile.SaveAs(Server.MapPath( "images\\BigImage\\ " + newname + newtype));
}
CopyTxt.Value = "SmallImage/ " + newname + newtype;
UploadPan.Visible=false;
UploadedPan.Visible = true;
}
}
}
}
===========================
Server Error in '/ ' Application.
--------------------------------------------
Parameter is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Parameter is not valid.
Source Error:
Line 43: + System.DateTime.Now.Day.ToString().Trim() + System.DateTime.Now.Hour.ToString().Trim() + System.DateTime.Now.Minute.ToString().Trim()
Line 44: + System.DateTime.Now.Second.ToString().Trim() + UploadFile.PostedFile.ContentLength;
Line 45: b=new System.Drawing.Bitmap(num);
Line 46:
Line 47: if(b.Width> 100)
Source File: d:\hosting\users\s155091\FS\OA\webs\UploadPic.aspx.cs Line: 45
Stack Trace:
[ArgumentException: Parameter is not valid.]
System.Drawing.Bitmap..ctor(String filename) +383669
FS_OA_webs_UploadPic.UploadBtn_Click(Object sender, EventArgs e) in d:\hosting\users\s155091\FS\OA\webs\UploadPic.aspx.cs:45
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
[解决办法]
沙发,帮忙顶
[解决办法]
好像你是参数有问题吧
[解决办法]
Server.MapPath( "images\\BigImage\\ " + newname + newtype
-----------路径有问题
[解决办法]
Source Error:
Line 43: + System.DateTime.Now.Day.ToString().Trim() + System.DateTime.Now.Hour.ToString().Trim() + System.DateTime.Now.Minute.ToString().Trim()
Line 44: + System.DateTime.Now.Second.ToString().Trim() + UploadFile.PostedFile.ContentLength;
Line 45: b=new System.Drawing.Bitmap(num);
Line 46:
Line 47:
这里的错误信息...你为什么不看呢???????
[解决办法]
if(b.Width> 100)
if(b.Width> 600)
为什么这样呢
当大于600的时候两个都执行其中的代码
小于100的时候都执行else里的代码
楼主的。。。。
[解决办法]
string newname=System.DateTime.Now.Year.ToString().Trim() + System.DateTime.Now.Month.ToString().Trim()
+ System.DateTime.Now.Day.ToString().Trim() + System.DateTime.Now.Hour.ToString().Trim() + System.DateTime.Now.Minute.ToString().Trim()
+ System.DateTime.Now.Second.ToString().Trim() ;
完全可以用DateTime.Now.ToString(yyyyMMddHHmmss);
代替
[解决办法]
很简单,是路径的问题,你现在程序获得的路径是【服务器的路径】,而在【客户端】上传找的是【服务器路径】;
解决很简单,你在服务器上新建一个文件夹,把要上传的图片先上传到文件夹中,然后在导入。导入后动态删除!!
[解决办法]
相对路径 就不会出错了
而且设置服务器的文件夹那的权限
~代码很不乐观啊~
[解决办法]
帮顶下!