用js或者提交后后台检测fileExt。
js:
后台:
<%
set upload=new upload_file
if upload.form("act")="uploadfile" then
filepath=trim(upload.form("filepath"))
filelx=trim(upload.form("filelx"))
i=0
for each formName in upload.File
set file=upload.File(formName)
fileExt=lcase(file.FileExt) '得到的文件扩展名不含有.
if file.filesize<100 then
response.write "请先选择你要上传的文件! [ 重新上传 ]"
response.end
end if
if (filelx<>"swf") and (filelx<>"jpg") then
'response.write "该文件类型不能上传! [ 重新上传 ]"
'response.end
response.write "" & VbCRLF
response.end
end if
if filelx="swf" then
if fileext<>"swf" then
'response.write "只能上传swf格式的Flash文件! [ 重新上传 ]"
'response.end
response.write "" & VbCRLF
response.end
end if
end if
if filelx="jpg" then
if fileext<>"gif" and fileext<>"jpg" and fileext<>"png" then
'response.write "只能上传jpg或gif格式的图片! [ 重新上传 ]"
'response.end
response.write "" & VbCRLF
response.end
end if
end if
if filelx="swf" then
if file.filesize>(3000*1024) then
'response.write "最大只能上传 3M 的Flash文件! [ 重新上传 ]"
'response.end
response.write "" & VbCRLF
response.end
end if
end if
if filelx="jpg" then
if file.filesize>(200*724) then
'response.write "最大只能上传 1000K 的图片文件! [ 重新上传 ]"
'response.end
response.write "" & VbCRLF
response.end
end if
end if
%>
要注意与上传控件一起配合好才行的。 有问题找偶。
你想要什么合法的路径?直接用文件上传组件就可以了,传回去的路径肯定是合法的,如果说你是想判断上传的图片是否合法,就在servlet里加一点判断就可以啦