<P>
<FORM id=form1 encType=multipart/form-data runat="server"></P>
<P><INPUT id=fileUp style="WIDTH: 80%" type=file name=fileUp runat="server"> </P>
<P></FORM></P>
/////////////////////////////////////////////////////////////////////////////////
string img = "";
string rnd = sqldata.rndNum(); //随机生成文件名
string filePath = "", fileExtName = "", mFileName, mPath, filetype;
if ("" != fileUp.PostedFile.FileName)
{
filePath = fileUp.PostedFile.FileName;//取得文件路径
fileExtName = filePath.Substring(filePath.LastIndexOf(".") + 1);
filetype = fileUp.PostedFile.ContentType.ToString();
if (filetype.Substring(0, 6) != "image/")
{
js.Alert("图片");
return;
}
try
{
mPath = Server.MapPath("../../pimages/" );
mFileName = filePath.Substring(filePath.LastIndexOf("\\") + 1); ;//取得文件名
fileUp.PostedFile.SaveAs(mPath + rnd + "." + fileExtName);
img = rnd + "." + fileExtName;
}
catch (Exception error)
{
Response.Write(error.ToString());
}
}
/////////////////////////////////////////////////////////////////////////////////