<script language="VBScript" type="text/vbscript"> NowFileInputNo = 1 NowFileInputCount = 0 Sub AddFileInput() If NowFileInputCount < 5 Then HTMLSrc = "
NowFileInputNo = 1
NowFileInputCount = 0
Sub AddFileInput()
If NowFileInputCount < 5 Then
HTMLSrc = "<table Id=FileInput"& NowFileInputNo &"><tr>"
HTMLSrc = HTMLSrc & "<td><input type='file' name='file"& NowFileInputNo &"' class='bk' size='30'> <input type='button' value='删除' class='bk' OnClick=""DelFileInput("& NowFileInputNo &")""></td></tr></table>"& vbcrlf
document.all.add_line.InsertAdjacentHTML "beforeBegin", HTMLSrc
NowFileInputNo = NowFileInputNo + 1
NowFileInputCount = NowFileInputCount + 1
Else
Alert "增加太多文件"
End IF
End Sub
Sub DelFileInput(tableno)
document.all("FileInput"& tableno).outerHTML = ""
NowFileInputCount = NowFileInputCount - 1
End Sub
</script>
<form id="form1" runat="server" enctype="multipart/form-data" method="post">
<TD style="WIDTH: 112px" align="right">产品图片:</TD>
<TD align="left"><INPUT class="bk" οnclick="AddFileInput()" type="button" value="添加照片" name="add_line"></TD>
Private Function Picdir() As String
Dim dirname As String = System.DateTime.Now.Year.ToString() & System.DateTime.Now.Month.ToString()
Dim dirpath = Server.MapPath("UploadImages/" & dirname)
If Directory.Exists(dirpath) = False Then
Directory.CreateDirectory(dirpath)
Return dirpath & "/"
Else
Return dirpath & "/"
End If
End Function
Private Function UpLoadPic() As String
Dim filePath, picPath As String
Dim i As Integer
filePath = Picdir()
picPath = ""
For i = 0 To Request.Files.Count - 1
Dim hpf As HttpPostedFile
hpf = Request.Files(i)
Dim fnx As Integer
fnx = hpf.FileName.Length
If fnx = 0 Then
Return ""
End If
Dim fx As String = hpf.FileName.Substring(fnx - 4, 4).ToLower()
If (fx <> ".jpg") And (fx <> ".gif") And (fx <> ".bmp") Then
Response.Write("<javascript lanage='javascript'>alert('增加的:'" & hpf.FileName & "不是图片!')</script>")
Return picPath
End If
Dim fn As String = System.DateTime.Now.ToString()
fn = fn.Replace(":", "")
fn = fn.Replace(" ", "")
Dim picErr As String
Try
hpf.SaveAs(filePath & fn & i.ToString() & fx)
picPath += filePath & fn & i.ToString() & fx & "#"
picErr = "图片上传成功!"
Catch ex As Exception
Response.Write(ex.ToString)
picErr = "图片上传失败!"
End Try
Next
Return picPath
End Function
//=========================================================================================================================
//检察目录
private string productPicdir()
{
string dirname = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString();
string dirpath = Server.MapPath("..//UploadedImages//product//" + dirname);
if (!Directory.Exists(Server.MapPath("..//UploadedImages//product//" + dirname)))
{
Directory.CreateDirectory(Server.MapPath("..//UploadedImages//product//" + dirname));
return dirpath + "//";
}
else
{
return dirpath + "//";
}
}
//=========================================================================================================================
//上传图片 返回图片路径
private string upLoadPic()
{
string filePath = productPicdir();
string picPath = "";
for (int i =0; i <=(Request.Files.Count - 1); i++)
{
//使用Request.Files()来逐个获取上传的文件
HttpPostedFile hpf;
hpf = Request.Files[i];
int fnx=hpf.FileName.Length;
if (fnx == 0)
{
return "";
}
string fx = hpf.FileName.Substring(fnx - 4, 4).ToLower();
if ((fx != ".jpg") && (fx != ".gif") && (fx != ".bmp"))
{
LTP.Common.MessageBox.Show(this, "增加的:"+hpf.FileName+"不是图片!");
return picPath;
}
string fn = System.DateTime.Now.ToString();
fn=fn.Replace(":", "");
fn = fn.Replace(" ", "");
try
{
hpf.SaveAs(filePath +fn+i.ToString()+fx);
picPath += filePath + fn + i.ToString() + fx + "#";
picErr = "图片上传成功!";
}
catch (Exception ex)
{
LTP.Common.MessageBox.Show(this, ex.ToString());
picErr = "图片上传失败!";
}
}
return picPath;
}