{
if(IsPostBack)
{
Boolean fileOK = false
String path = Server.MapPath("~/UploadedImages/")
if (FileUpload1.HasFile)
{
String fileExtension =
System.IO.Path.GetExtension(FileUpload1.FileName).ToLower()
String[] allowedExtensions =
{".gif", ".png", ".jpeg", ".jpg"}
for (int i = 0i <allowedExtensions.Lengthi++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true
}
}
}
if (fileOK)
{
try
{
FileUpload1.PostedFile.SaveAs(path
+ FileUpload1.FileName)
Label1.Text = "File uploaded!"
}
catch (Exception ex)
{
Label1.Text = "File could not be uploaded."
}
}
else
{
Label1.Text = "Cannot accept files of this type."
}
}
}
那只有把这段代码写两次,第一次判断是否合法(不要else),第二次执行上传(不要if),例如:
$kuozhan=array('jpg','gif','doc')foreach($val['tmp_name'] as $key=>$us){
foreach($val['name'] as $key=>$ns){
$arr=pathinfo($val['name'][$key])
if(!in_array($arr['extension'],$kuozhan)){
echo " 上传失败,格式错误!"
return false
}
}
foreach($val['tmp_name'] as $key=>$us){
foreach($val['name'] as $key=>$ns){
$arr=pathinfo($val['name'][$key])
上传程序
}}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)