Gente, estou com uma dificuldade incrível com este upload. Vou colocar o código abaixo mas antes vou explicar oq a página faz.
É uma página de inserção de notícias onde o usuário vai ter três opções de notícia:
- 1 com foto
- 2 e 3 sem foto
O meu problema é o seguinte: Se ele seleciona a 1ª opção ele faz o upload certinho, grava no bd o caminho e tudo mais. Só que se ele seleciona a segunda opção ou a terceira eu não estou conseguindo bloquear o upload para não dar paw, pois não há nenhum arquivo.
Alguém tem alguma idéia??

o código segue abaixo.
Valew pessoal
JucaMaster
------------------------------------------------------------------------------------------------------------------------------------------
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% option explicit%>
<!--#include file = "include/conexao.asp"-->
<%
if Request.ServerVariables("CONTENT_LENGTH")<>0 and Request.ServerVariables("REQUEST_METHOD") = "POST" then
Dim PegaAssunto,PegaNoticia,PegaTipoNoticia,PegaImagem
Call abre_conn()
DIM Conn,strsql
'declara as variáveis
dim objUpload
dim strMessage
'cria instância do objeto
set objUpload = server.CreateObject("Persits.Upload")
'verifica um possível erro
if err.number <> 0 then
Response.Redirect "teste.asp?Message=" & err.description
end if
'informa o path onde os arquivos serão salvos
dim temp
objUpload.Save server.MapPath("imagens/")
PegaAssunto = objUpload.Form("txtAssunto")
PegaNoticia = objUpload.Form("txtNoticia")
PegaTipoNoticia = objUpload.Form("optTipoNoticia")
Dim Files
Set Files = objUpload.Files("THEFILE")
PegaImagem="imagens/" & objUpload.Files("txtImagem").filename
PegaAssunto = Trim(Replace(PegaAssunto,"'",""))
PegaNoticia = Trim(Replace(PegaNoticia,"'",""))
RESPONSE.WRITE "SUCESSO"
strsql = "insert into tb_news (usuario,assunto,noticia,tipo_noticia,imagem_noticia) values('" & session("nome") & "','" & PegaAssunto & "','" & PegaNoticia & "','" & PegaTipoNoticia & "','" & PegaImagem & "')"
Conn.execute(strsql)
strMessage = "Upload realizado com sucesso!!"
Response.Redirect "mensagem.asp?Message=" & strMessage
'destroi o objeto
set objUpload = nothing
call fecha_conn()
end if
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR...ml4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 9px;
color: #000000;
}
.style2 {
font-family: Arial, Helvetica, sans-serif;
font-size: 2;
color: #666666;
font-weight: bold;
}
.botaobr {BORDER: #000000 1px solid; COLOR: #000000; 1px solid; HEIGHT: 20px; background-color: #FFFFFF;}
.style23 {font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 7pt;
}
.style24 {
color: #999999;
font-weight: bold;
}
-->
</style>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data" name="form1" onSubmit="return valida()">
<table width="100%" border="1" align="center" cellpadding="4" cellspacing="0" bordercolor="#FF6600">
<tr bgcolor="#EBEBE1">
<td colspan="4"><div align="center" class="style2">Inserção de notícias </div></td>
</tr>
<tr>
<td width="11%"><div align="left"><span class="style1">usuário</span></div></td>
<td colspan="3" class="style23 style24"><font color="#FF6600" size="1" face="Verdana, Arial, Helvetica, sans-serif"><strong><%=session("nome")%></strong></font></td>
</tr>
<tr>
<td class="style1">assunto</td>
<td colspan="3"><input name="txtAssunto" type="text" id="txtAssunto" size="54"></td>
</tr>
<tr>
<td class="style1">notícia</td>
<td colspan="3"><textarea name="txtNoticia" cols="50" rows="7" wrap="VIRTUAL" id="txtNoticia"></textarea></td>
</tr>
<tr>
<td class="style1">tipo da notícia</td>
<td width="26%" valign="middle" class="style1">
<div align="left">
<input name="optTipoNoticia" type="radio" value="1">
1- com foto e descriçao </div></td>
<td width="34%" align="center" valign="middle" class="style1"><input name="optTipoNoticia" type="radio" value="2">
2- apenas com descrição</td>
<td width="29%" valign="middle" class="style1"><input name="optTipoNoticia" type="radio" value="3">
3-pequena </td>
</tr>
<tr>
<td class="style1">imagem da notícia</td>
<td colspan="3"><input name="txtImagem" type="file" class="botaobr"></td>
</tr>
<tr>
<td colspan="4"><div align="center">
<span class="style23">
<input name="Submit" type="submit" class="botaobr" value="enviar" onClick="return valida()">
<input name="Submit2" type="button" class="botaobr" value="voltar" onClick="history.back()">
</span></div></td>
</tr>
</table>
</form>
</body>
</html>
<script language="javascript">
function valida()
{
if (document.form1.txtAssunto.value=="")
{
alert("Digite o assunto");
document.form1.txtAssunto.focus();
return false;
}
if (document.form1.txtNoticia.value=="")
{
alert("Digite a notícia");
document.form1.txtNoticia.focus();
return false;
}
if (!document.form1.optTipoNoticia[0].checked && !document.form1.optTipoNoticia[1].checked && !document.form1.optTipoNoticia[2].checked)
{
alert("Selecione um tipo de notícia");
document.form1.optTipoNoticia.focus();
return false;
}
if(document.form1.optTipoNoticia[0].checked && document.form1.txtImagem.value=="")
{
alert("Se você selecionou o primeiro tipo de notícia \n você deve indicar uma imagem")
document.form1.txtImagem.focus();
return false;
}
document.form1.submit()
}
</script>