Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

marcosbeltrami

Sistema de Upload com outros dados do formulário

Recommended Posts

Olá pessoal, sou iniciante em asp e tenho um sistema de inclusão de dados e de imagens no banco de dados (isso mesmo, as imagens estão incluídas dentro do banco), só que quero mudar isso, então se alguém puder me ajudar eu agradeço.

 

Gostaria que na hora que eu fosse incluir a notícia no site, os dados dela fossem incluídos no banco de dados, bem como o caminho da imagem, e que as imagens fossem para uma pasta específica e nela ainda teria mais 2 pastas, uma com a imagem da chamada (imagem pequena) e outra com a imagem da notícia (imagem grande), tem como fazer isso?

 

Obs: a minha hospedagem não tem nenhum componente de upload.

 

Segue abaixo a página de inclusão:

 

ASP

[*]<form action="gravar.asp" method="POST" enctype="multipart/form-data" name="form1">

 

[*]<tr>

 

[*] <td class="mdtextbold">Título:</td>

 

[*] <td><input name="not_titulo" type="text" class="mdtext" id="not_titulo" size="80" maxlength="255"></td>

 

[*]</tr>

 

[*]<tr>

 

[*] <td height="15"></td>

 

[*] <td></td>

 

[*]</tr>

 

[*]<tr>

 

[*] <td valign="top" class="mdtextbold">Texto:</td>

 

[*] <td><textarea name="not_texto" cols="100" rows="10" id="not_texto" class="mdtext"></textarea></td>

 

[*]</tr>

 

[*]<tr>

 

[*] <td height="15"></td>

 

[*] <td></td>

 

[*]</tr>

 

[*]<tr>

 

[*] <td class="mdtextbold">Img Chamada:</td>

 

[*] <td class="preto"><input type="file" name="cimg" class="mdtext"> <span class="mdtext">(A largura não pode passar de 100 pixels)</span></td>

 

[*]</tr>

 

[*]<tr>

 

[*] <td height="15"></td>

 

[*] <td></td>

 

[*]</tr>

 

[*]<tr>

 

[*] <td class="mdtextbold">Img Notícia:</td>

 

[*] <td class="preto"><input type="file" name="nimg" class="mdtext"> <span class="mdtext">(A largura não pode passar de 250 pixels)</span></td>

 

[*]</tr>

 

[*]<tr>

 

[*] <td height="15"></td>

 

[*] <td></td>

 

[*]</tr>

 

[*]<tr>

 

[*] <td height="15" colspan="2"><div align="center">

 

[*] <input name="acao" type="hidden" id="acao" value="gravar">

 

[*] <input type="submit" name="Submit" value=" INCLUIR " class="mdtext">

 

[*] </div></td>

 

[*]</tr>

 

[*]</form>

 

A página de gravação: (desculpem-me colar o código inteiro da página, mas não sei que parte eu teria que colocar para que vcs possam me ajudar)

 

ASP

[*]<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

 

[*]<!--#'include file="../acesso6.asp"-->

 

[*]<%

 

[*]session.LCID = 1046

 

[*]%>

 

[*]<!--#include file="../../includes/loader.asp"-->

 

[*]<%

 

[*]

 

[*]'Option Explicit

 

[*]Dim acao, not_titulo, not_texto

 

[*]Dim Conn, rsnot, rsnimg, rscimg

 

[*]Dim nimg_id, cimg_id, not_id

 

[*]Dim not_nimg_id, not_cimg_id

 

[*]Dim apaga_cimg, apaga_nimg

 

[*]Dim SQLdel1, SQLdel2, SQLdel3

 

[*]

 

[*]'***** Recupera os dados do formulario not_incluir.asp

 

[*]Set load = new Loader

 

[*] ' calling initialize method

 

[*]load.initialize

 

[*] ' File binary data

 

[*]acao load.getValue("acao")

 

[*]

 

[*]'***** APAGA REGISTRO *****

 

[*]if acao "apagar" then

 

[*]not_id load.getValue("not_id")

 

[*]not_nimg_id load.getValue("not_nimg_id")

 

[*]not_cimg_id load.getValue("not_cimg_id")

 

[*]

 

[*]SQLdel1 "DELETE FROM noticias WHERE not_id = "& not_id &";"

 

[*]SQLdel2 "DELETE FROM noticias_nimg WHERE nimg_id ="& not_nimg_id &";"

 

[*]SQLdel3 "DELETE FROM noticias_cimg WHERE cimg_id ="& not_cimg_id &";"

 

[*]

 

[*]'***** Abre conexao com o bd *****

 

[*]Set Conn Server.CreateObject("ADODB.Connection")

 

[*]'Conn.CursorLocation = 2

 

[*]Conn.open application("conexao")

 

[*]Set rsapagar Conn.execute(SQLdel1)

 

[*]Set rsapagar = nothing

 

[*] if not_nimg_id <> "" then

 

[*] Set rsapagar Conn.execute(SQLdel2)

 

[*] Set rsapagar = nothing

 

[*] end if

 

[*] if not_cimg_id <> "" then

 

[*] Set rsapagar Conn.execute(SQLdel3)

 

[*] Set rsapagar = nothing

 

[*] end if

 

[*]Set Conn = Nothing

 

[*]response.redirect("listar.asp")

 

[*]end if

 

[*]

 

[*]if acao "alterar" then

 

[*]not_id load.getValue("not_id")

 

[*]not_nimg_id load.getValue("not_nimg_id")

 

[*]not_cimg_id load.getValue("not_cimg_id")

 

[*]apaga_cimg load.getValue("apaga_cimg")

 

[*]apaga_nimg load.getValue("apaga_nimg")

 

[*]end if

 

[*]not_titulo replace(load.getValue("not_titulo"),"'","''")

 

[*]not_texto replace(load.getValue("not_texto"),"'","''")

 

[*]'***** Abre conexao com o bd *****

 

[*]Set Conn Server.CreateObject("ADODB.Connection")

 

[*]'Conn.CursorLocation = 2

 

[*]Conn.open application("conexao")

 

[*]

 

[*]'***** Recupera dados da imagem da Noticia CIMG *****

 

[*]cimg2 load.getFileData("cimg")

 

[*]if cimg2 <> "" then

 

[*]' File binary data

 

[*] Dim cimg_bin

 

[*] cimg_bin load.getFileData("cimg")

 

[*]' File name

 

[*] Dim cimg_nome

 

[*] cimg_nome LCase(load.getFileName("cimg"))

 

[*]' File size

 

[*] Dim cimg_tamanho

 

[*] cimg_tamanho load.getFileSize("cimg")

 

[*]' Content Type

 

[*] Dim cimg_tipo

 

[*] cimg_tipo load.getContentType("cimg")

 

[*]' destroying load object

 

[*]' Set load = Nothing

 

[*]

 

[*]'***** Cria o Recordset cimg *****

 

[*]if acao "gravar" or (acao="alterar" and not_cimg_id ""then

 

[*]Set rscimg Server.CreateObject("ADODB.Recordset")

 

[*]with rscimg

 

[*] .Source "noticias_cimg"

 

[*] .ActiveConnection = Conn

 

[*] .CursorType = 1

 

[*] .LockType = 2

 

[*] .Open

 

[*] .Addnew

 

[*] .fields("cimg_nome"= cimg_nome

 

[*] .fields("cimg_tamanho"= cimg_tamanho

 

[*] .fields("cimg_bin").AppendChunk cimg_bin

 

[*] .fields("cimg_tipo"= cimg_tipo

 

[*] .Update

 

[*] not_cimg_id .fields("cimg_id")

 

[*]end with

 

[*]Set rscimg = nothing

 

[*]end if

 

[*]if acao "alterar" and not_cimg_id <>"" then

 

[*]Set rscimg Server.CreateObject("ADODB.Recordset")

 

[*]SQLcimg "SELECT * FROM noticias_cimg WHERE cimg_id ="& not_cimg_id &";"

 

[*]with rscimg

 

[*] .Source "noticias_cimg"

 

[*] .ActiveConnection = Conn 

 

[*] .CursorType = 1

 

[*] .LockType = 2

 

[*] .Open SQLcimg

 

[*] .fields("cimg_nome"= cimg_nome

 

[*] .fields("cimg_tamanho"= cimg_tamanho

 

[*] .fields("cimg_bin").AppendChunk cimg_bin

 

[*] .fields("cimg_tipo"= cimg_tipo

 

[*] .Update

 

[*] not_cimg_id .fields("cimg_id")

 

[*]end with

 

[*]Set rscimg = nothing

 

[*]end if

 

[*]end if

 

[*]

 

[*]

 

[*]'***** Recupera dados da imagem da Noticia NIMG*****

 

[*]nimg2 load.getFileData("nimg")

 

[*]if nimg2 <> "" then

 

[*] ' File binary data

 

[*] Dim nimg_bin

 

[*] nimg_bin load.getFileData("nimg")

 

[*] ' File name

 

[*] Dim nimg_nome

 

[*] nimg_nome LCase(load.getFileName("nimg"))

 

[*] ' File size

 

[*] Dim nimg_tamanho

 

[*] nimg_tamanho load.getFileSize("nimg")

 

[*] ' Content Type

 

[*] Dim nimg_tipo

 

[*] nimg_tipo load.getContentType("nimg")

 

[*]

 

[*]'***** Cria o Recordset nimg *****

 

[*]if acao "gravar" or (acao="alterar" and not_nimg_id ""then

 

[*]Set rsnimg Server.CreateObject("ADODB.Recordset")

 

[*]With rsnimg

 

[*] .Source "noticias_nimg"

 

[*] .ActiveConnection = Conn

 

[*] .CursorType = 1

 

[*] .LockType = 2

 

[*] .Open

 

[*] .Addnew

 

[*] .Fields("nimg_nome"= nimg_nome

 

[*] .Fields("nimg_tamanho"= nimg_tamanho

 

[*] .Fields("nimg_bin").AppendChunk nimg_bin

 

[*] .Fields("nimg_tipo"= nimg_tipo

 

[*] .Update

 

[*] not_nimg_id .Fields("nimg_id")

 

[*]End With

 

[*]Set rsnimg = nothing

 

[*]end if

 

[*]

 

[*]if acao "alterar" and not_nimg_id <>"" then

 

[*]Set rsnimg Server.CreateObject("ADODB.Recordset")

 

[*]SQLnimg "SELECT * FROM noticias_nimg WHERE nimg_id = "& not_nimg_id &";"

 

[*]With rsnimg

 

[*] .Source "noticias_nimg"

 

[*] .ActiveConnection = Conn

 

[*] .CursorType = 1

 

[*] .LockType = 2

 

[*] .Open SQLnimg

 

[*] .Fields("nimg_nome"= nimg_nome

 

[*] .Fields("nimg_tamanho"= nimg_tamanho

 

[*] .Fields("nimg_bin").AppendChunk nimg_bin

 

[*] .Fields("nimg_tipo"= nimg_tipo

 

[*] .Update

 

[*] not_nimg_id .Fields("nimg_id")

 

[*]End With

 

[*]not_nimg_id cint(not_nimg_id)

 

[*]Set rsnimg = nothing

 

[*]end if

 

[*]end if

 

[*]

 

[*]'***** Cria o Recordset noticias *****

 

[*]if acao "gravar" then

 

[*]Set rsnot Server.CreateObject("ADODB.Recordset")

 

[*]with rsnot

 

[*] .Source "noticias"

 

[*] .ActiveConnection = Conn

 

[*] .CursorType = 1

 

[*] .LockType = 2

 

[*] .Open

 

[*] .Addnew

 

[*] .fields("not_titulo"= not_titulo

 

[*] .fields("not_texto"= not_texto

 

[*] .fields("not_cimg_id"= not_cimg_id

 

[*] .fields("not_nimg_id"= not_nimg_id

 

[*] .Update

 

[*]end with

 

[*]Set rsnot = nothing

 

[*]end if

 

[*]

 

[*]if acao "alterar" then

 

[*]SQLnot1 "SELECT * FROM noticias WHERE not_id = "& not_id &";"

 

[*]Set rsnot Server.CreateObject("ADODB.Recordset")

 

[*]with rsnot

 

[*] .Source "noticias"

 

[*] .ActiveConnection = Conn

 

[*] .CursorType = 1

 

[*] .LockType = 2

 

[*] .Open SQLnot1

 

[*] .fields("not_titulo"= not_titulo

 

[*] .fields("not_texto"= not_texto

 

[*]end with

 

[*]if not_cimg_id <> "" and apaga_cimg <> "sim" then

 

[*] rsnot("not_cimg_id"= not_cimg_id

 

[*]end if

 

[*]if not_nimg_id <> "" and apaga_nimg <>"sim"then 

 

[*] rsnot("not_nimg_id"= not_nimg_id

 

[*]end if

 

[*]if apaga_cimg "sim" then

 

[*] rsnot("not_cimg_id"= null

 

[*]end if

 

[*]if apaga_nimg "sim" then

 

[*] rsnot("not_nimg_id"= null

 

[*]end if

 

[*] rsnot.Update

 

[*]Set rsnot = nothing

 

[*]

 

[*]'***** Apaga registro em cimg *****

 

[*]if apaga_cimg "sim" then

 

[*]SQLdel2 "DELETE FROM noticias_cimg WHERE cimg_id ="& not_cimg_id &";"

 

[*]Set rsapagar Conn.execute(SQLdel2)

 

[*]Set rsapagar = nothing

 

[*]end if

 

[*]

 

[*]'***** Apaga registro em nimg *****

 

[*]if apaga_nimg "sim" then

 

[*]SQLdel3 "DELETE FROM noticias_nimg WHERE nimg_id ="& not_nimg_id &";"

 

[*]Set rsapagar Conn.execute(SQLdel3)

 

[*]Set rsapagar = nothing

 

[*]end if

 

[*]

 

[*]end if

 

[*]

 

[*]'***** Fecha a conexao *****

 

[*]conn.close

 

[*]set conn = nothing

 

[*]set load = nothing

 

[*]

 

[*]'****** redireciona para onde veio *****

 

[*]if acao "gravar" then

 

[*] RESPONSE.Redirect("incluir.asp")

 

[*]elseif acao "alterar" then

 

[*] RESPONSE.Redirect("listar.asp")

 

[*]end if

 

[*]%>

 

Obrigado,

 

Marcos Beltrami

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.