Sistema Noticias, Com Imagens
#1
Posted 12/09/2004, 01:26
Como incluir o comando para enviar uma imagem, e depois mostrar a materia com a imagem.
Tenho aqui o sistema que ADICIONA a NOTICIA, agora só resta alterar para enviar uma imagem também
PHP |
<?php include("verificar.php"); $mesnome[1] = "janeiro"; $mesnome[2] = "fevereiro"; $mesnome[3] = "março"; $mesnome[4] = "abril"; $mesnome[5] = "maio"; $mesnome[6] = "junho"; $mesnome[7] = "julho"; $mesnome[8] = "agosto"; $mesnome[9] = "setembro"; $mesnome[10] = "outubro"; $mesnome[11] = "novembro"; $mesnome[12] = "dezembro"; $ano = date('Y'); $mes = date('n'); $dia = date('d'); $diasem = date('w'); $hora=getdate(); $horacerta=($hora['hours'].' e '.$hora['minutes']); $data = ''.$dia.' de '.$mesnome[$mes].' de '.$ano.' às '.$horacerta .' minutos'; ?> <html> <head> <title>Adicionar Matéria</title> </head> <script language="JavaScript"> <!-- limite=200; function soma() { var mais_um=eval(document.form.caracteres.value.length-1); mais_um++; if (document.form.caracteres.value.length>limite) { document.form.caracteres.value=''; document.form.caracteres.value=valor_limite; alert("Limite de "+limite+" caracteres"); }else{ document.form.exibe.value=''; document.form.exibe.value=eval(mais_um); valor_limite=document.form.caracteres.value; document.form.exibe2.value=''; document.form.exibe2.value=(limite-mais_um); } document.form.caracteres.focus(); } function mostra_tamanho(){ document.form.exibe2.value=limite; } //--> </script> <body onLoad="mostra_tamanho()"> <form name=form method="POST" action="index.php?page=add_db"> <table align=center border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="322" id="AutoNumber2" height="12"> <tr> <td width="105" height="1"><font size="1" face="Verdana"><b>Titulo da Matéria: </b></font></td> <td width="217" height="1"><font size="1" face="Verdana"><b> <input type="text" name="titulo" size="20" style="font-family: Verdana; font-size: 10 px; color: #808080; border: 1px solid #C0C0C0"></b></font></td> </tr> <tr> <td width="105" height="1"><b><font face="Verdana" size="1">Base do estudo:</font></b></td> <td width="217" height="1"><font size="1" face="Verdana"><b> <input type="text" name="base" size="42" style="font-family: Verdana; font-size: 10 px; color: #808080; border: 1px solid #C0C0C0"></b></font></td> </tr> <tr> <td width="322" colspan="2" height="1"> <p align="center"><b><font face="Verdana" size="1">Breve discrição (Max. de 200 caracteres)</font></b></td> </tr> <tr> <td width="322" colspan="2" height="1"> <p align="center"> <textarea cols="54" rows="6" name="caracteres" onKeyPress="soma(this.value)" onKeyUp="soma(this.value)" style="font-family: Verdana; font-size: 10 px; color: #808080; border: 1px solid #C0CFDF"></textarea></td> </tr> <tr> <td width="322" colspan="2" valign="middle" height="1"> <p align="center"><font face="Verdana" size="1">Digitado | <b>Faltam </b></font></td> </tr> <tr> <td width="322" colspan="2" valign="middle" height="1"> <p align="center"> <input type="text" name="exibe" size="5" maxlength="10" style="font-family: Verdana; font-size: 10 px; font-weight: bold; border: 1px solid #C0CFDF"> <input type="text" name="exibe2" size="5" maxlength="10" style="font-family: Verdana; font-size: 10 px; font-weight: bold; border: 1px solid #C0CFDF"></td> </tr> <tr> <td width="322" colspan="2" height="1"></td> </tr> <tr> <td width="322" colspan="2" height="13"> <p align="center"> <font size="1" face="Verdana"><b> <input type="text" name="data" size="50" style="font-family: Verdana; font-size: 10 px; color: #808080; border: 1px solid #F7F7F7; background: #f7f7f7; " value="<?echo $data; ?>"</font></tr> <tr> <td width="322" colspan="2" height="18"> <p align="center"><u><b><font face="Verdana" size="1">Digite a Matéria!</font></b></u></tr> <tr> <td width="322" colspan="2" height="7"> <textarea name="texto" cols="38" rows="18"></textarea> </tr> <tr> <td width="322" colspan="2" height="19"> <p align="center"> <input type="submit" value="Submeter" name="B1" style="font-family: Verdana; font-size: 10 px; font-weight: bold; border: 1px solid #C0CFDF"> <input type="reset" value="Redefinir" name="B2" style="font-family: Verdana; font-size: 10 px; border: 1px solid #C0CFDF"></tr> </tr> </table> </form> </body> </html> |
Aqui é o sistema que mostra a NOTICIA
agora falta incluir o sistema que também mostra a imagem a qual pertence a materia
PHP |
<?php include("config.php"); $sql = "SELECT * FROM materias WHERE id=$id"; $resultado = mysql_query($sql) or die ("Não foi possível realizar a consulta ao banco de dados"); while ($linha=mysql_fetch_array($resultado)) { $id = $linha["id"]; $titulo = $linha["titulo"]; $base = $linha["base"]; $data = $linha["data"]; $texto = nl2br($linha["texto"]); $descricao = $linha["descricao"]; echo "<title>Exibindo Matéria: $titulo</title>"; echo "<div align=center> <table width=405 border=0 cellpadding=0 cellspacing=0> <!--DWLayoutTable--> <tr> <td width=405 height=35 align=center valign=middle><img src=../icone_titulo1.gif width=16 height=16 align=absmiddle><font color=#333333 size=2 face=Verdana, Arial, Helvetica, sans-serif><strong> $titulo</strong></font></td> </tr> <tr> <td height=17 align=center valign=top><font color=#000000 size=2 face=Verdana, arial, helvetica, sans-serif>$texto</font></td> </tr> <tr> <td height=20 align=center valign=top><!--DWLayoutEmptyCell--> </td> </tr> <tr> <td height=13 valign=top><div align=center><a href=/mensagems><img src=../icone_voltar.gif alt=Ver_Todas_Mensagens width=92 height=21 border=0></a></div></td> </tr> </table> </div>"; } ?> |
#2
Posted 12/09/2004, 05:23
1- Colocar o campo para upload no formulário.
2- Receber o arquivo pela variável $_FILES["nome_do_campo"].
3- Fazer a validação do mime/type do arquivo, para aceitar somente imagens ou quaisquer outros que você deseje, usando a variável $_FILES["nome_do_campo"]["type"].
4- Fazer a validação do tamanho, usando a variável $_FILES["nome_do_campo"]["size"];
5- Mover o arquivo "uploadeado" que está na pasta temporária do server, com o comando move_uploaded_file, com a sintaxe a seguir:
$nome_da_imagem = md5 (microtime());
move_uploaded_file ($_FILES["nome_do_campo"]["tmp_name"], "/Uploads/" . $nome_da_imagem . ".jpg");
6- Gravar no BD o "$nome_da_imagem".
Notas: No passo 5, repare que eu automaticamente defini a extensão do arquivo como .jpg. Você pode querer assim ou não... Você pode criar uma variável para definir o tipo de extensão baseando-se no mime/type do arquivo.
$extensao = ($_FILES["nome_do_campo"]["type"] == "image/gif") ? ".gif" : ".jpg";
#3
Posted 12/09/2004, 07:45
#4
Posted 12/09/2004, 08:01
Você já tem o arquivo de validação para eu modificar ae também ou não fez??
<?php
include("verificar.php");
$mesnome[1] = "janeiro";
$mesnome[2] = "fevereiro";
$mesnome[3] = "março";
$mesnome[4] = "abril";
$mesnome[5] = "maio";
$mesnome[6] = "junho";
$mesnome[7] = "julho";
$mesnome[8] = "agosto";
$mesnome[9] = "setembro";
$mesnome[10] = "outubro";
$mesnome[11] = "novembro";
$mesnome[12] = "dezembro";
$ano = date('Y');
$mes = date('n');
$dia = date('d');
$diasem = date('w');
$hora=getdate();
$horacerta=($hora['hours'].' e '.$hora['minutes']);
$data = ''.$dia.' de '.$mesnome[$mes].' de '.$ano.' às '.$horacerta .' minutos';
?>
<html><head><title>Adicionar Matéria</title>
</head>
<script language="JavaScript">
<!--
limite=200;
function soma() {
var mais_um=eval(document.form.caracteres.value.length-1);
mais_um++;
if (document.form.caracteres.value.length>limite) {
document.form.caracteres.value='';
document.form.caracteres.value=valor_limite;
alert("Limite de "+limite+" caracteres");
}else{
document.form.exibe.value='';
document.form.exibe.value=eval(mais_um);
valor_limite=document.form.caracteres.value;
document.form.exibe2.value='';
document.form.exibe2.value=(limite-mais_um);
}
document.form.caracteres.focus();
}
function mostra_tamanho(){
document.form.exibe2.value=limite;
}
//-->
</script>
<body onLoad="mostra_tamanho()">
<form name=form method="POST" action="index.php?page=add_db">
<table align=center border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="322" id="AutoNumber2" height="12">
<tr>
<td width="105" height="1"><font size="1" face="Verdana"><b>Titulo da Matéria:
</b></font></td>
<td width="217" height="1"><font size="1" face="Verdana"><b>
<input type="text" name="titulo" size="20" style="font-family: Verdana; font-size: 10 px; color: #808080; border: 1px solid #C0C0C0"></b></font></td>
</tr>
<tr>
<td width="105" height="1"><b><font face="Verdana" size="1">Base do estudo:</font></b></td>
<td width="217" height="1"><font size="1" face="Verdana"><b>
<input type="text" name="base" size="42" style="font-family: Verdana; font-size: 10 px; color: #808080; border: 1px solid #C0C0C0"></b></font></td>
</tr>
<tr>
<td width="105" height="1"><b><font face="Verdana" size="1">Arquivo:</font></b></td>
<td width="217" height="1"><font size="1" face="Verdana"><b>
<input type="file" name="file" size="42" style="font-family: Verdana; font-size: 10 px; color: #808080; border: 1px solid #C0C0C0"></b></font></td>
</tr>
<tr>
<td width="322" colspan="2" height="1">
<p align="center"><b><font face="Verdana" size="1">Breve discrição
(Max. de 200 caracteres)</font></b></td>
</tr>
<tr>
<td width="322" colspan="2" height="1">
<p align="center">
<textarea cols="54" rows="6" name="caracteres" onKeyPress="soma(this.value)" onKeyUp="soma(this.value)" style="font-family: Verdana; font-size: 10 px; color: #808080; border: 1px solid #C0CFDF"></textarea></td>
</tr>
<tr>
<td width="322" colspan="2" valign="middle" height="1">
<p align="center"><font face="Verdana" size="1">Digitado | <b>Faltam
</b></font></td>
</tr>
<tr>
<td width="322" colspan="2" valign="middle" height="1">
<p align="center">
<input type="text" name="exibe" size="5" maxlength="10" style="font-family: Verdana; font-size: 10 px; font-weight: bold; border: 1px solid #C0CFDF">
<input type="text" name="exibe2" size="5" maxlength="10" style="font-family: Verdana; font-size: 10 px; font-weight: bold; border: 1px solid #C0CFDF"></td>
</tr>
<tr>
<td width="322" colspan="2" height="1"></td>
</tr>
<tr>
<td width="322" colspan="2" height="13">
<p align="center">
<font size="1" face="Verdana"><b>
<input type="text" name="data" size="50" style="font-family: Verdana; font-size: 10 px; color: #808080; border: 1px solid #F7F7F7; background: #f7f7f7; " value="<?echo $data; ?>"</font></tr>
<tr>
<td width="322" colspan="2" height="18">
<p align="center"><u><b><font face="Verdana" size="1">Digite a
Matéria!</font></b></u></tr>
<tr>
<td width="322" colspan="2" height="7">
<textarea name="texto" cols="38" rows="18"></textarea>
</tr>
<tr>
<td width="322" colspan="2" height="19">
<p align="center">
<input type="submit" value="Submeter" name="B1" style="font-family: Verdana; font-size: 10 px; font-weight: bold; border: 1px solid #C0CFDF">
<input type="reset" value="Redefinir" name="B2" style="font-family: Verdana; font-size: 10 px; border: 1px solid #C0CFDF"></tr>
</tr>
</table>
</form>
</body>
</html>
[...] ó terra, terra, terra; ouve a palavra do Senhor. — Jeremias 22:29
#5
Posted 12/09/2004, 09:02
O código completo fica com a combinação do que você já tem, mais o que eu expliquei acima.intaum como fica o código completo???
#6
Posted 12/09/2004, 13:32
O Felipe colocou o campo de formulario certo.
Agora, não tem que mandar a imagem?
Edição feita por: gregorytg, 12/09/2004, 13:36.
#7
Posted 12/09/2004, 13:36
[...] ó terra, terra, terra; ouve a palavra do Senhor. — Jeremias 22:29
#8
Posted 12/09/2004, 13:39
PHP |
<?php include("verificar.php"); include ("../config.php"); $sql = "INSERT INTO materias (titulo, texto, base, descricao, data) VALUES ('$titulo', '$texto', '$base', '$caracteres', '$data')"; $sql = mysql_query($sql) or die ("Houve erro na gravação dos dados, por favor, clique em voltar e verifique os campos obrigatórios!"); echo "<font color=#404040><b>Noticia Adicionada com Sucesso!</b></font>"; ?> |
#9
Posted 12/09/2004, 14:47
PHP |
<?php include("verificar.php"); include ("../config.php"); $dir = "pasta/"; //aonde ficará as imagens $imagem_name = $_FILES['file']['name']; $imagem_tmp = $_FILES['file']['tmp_name']; $imagem = $dir.$imagem_name; if ($imagem_name) { $u = move_uploaded_file($imagem_tmp, $imagem); echo ($u==true) ? "" : "Erro ao enviar arquivo!"; } $sql = mysql_query("INSERT INTO materias (titulo, texto, base, descricao, data, imagem) VALUES ('$titulo', '$texto', '$base', '$caracteres', '$data','$imagem')"); if ($sql==false) { echo ("Houve erro na gravação dos dados, por favor, clique em voltar e verifique os campos obrigatórios!"); } else { echo "<font color=#404040><b>Noticia Adicionada com Sucesso!</b></font>"; } ?> |
[...] ó terra, terra, terra; ouve a palavra do Senhor. — Jeremias 22:29
#10
Posted 12/09/2004, 16:31
e como eu mostra a Noticia com a Imagem?
e EU preciso dar alguem CHMOD para a pasta que vai fikar as imagens?
#11
Posted 12/09/2004, 16:47
Para ver as noticias testa isso ae...
Ver.php
<?php
//Coloca a conexao e a seleção do BD
$id = $HTTP_GET_VARS['id'];
if (empty($id)) {
$cons = mysql_query("SELECT * FROM materias");
while($o=mysql_fetch_object($cons)){
echo "<a href=\"ver.php?id=".$o->id."\">".$o->titulo."</a><br />";
}
}
else {
$consID = mysql_query("SELECT * FROM materias WHERE id='".$id."'");
while($oo=mysql_fetch_object($consID)){
echo $oo->titulo."<br />";
echo $oo->imagem."<br />";
echo $oo->texto."<br />";
}
}
?>
Você tá usando ID né?!
[...] ó terra, terra, terra; ouve a palavra do Senhor. — Jeremias 22:29
#12
Posted 12/09/2004, 16:49
PHP |
<?php include("config.php"); $sql = "SELECT * FROM materias WHERE id=$id"; $resultado = mysql_query($sql) or die ("Não foi possível realizar a consulta ao banco de dados"); while ($linha=mysql_fetch_array($resultado)) { $id = $linha["id"]; $titulo = $linha["titulo"]; $base = $linha["base"]; $data = $linha["data"]; $texto = nl2br($linha["texto"]); $descricao = $linha["descricao"]; $imagem = $linha ["imagem"]; echo "<title>Exibindo Matéria: $titulo</title>"; echo "<div align=center> <table width=405 border=0 cellpadding=0 cellspacing=0> <!--DWLayoutTable--> <tr> <td width=405 height=35 align=center valign=middle><img src=../icone_titulo1.gif width=16 height=16 align=absmiddle><font color=#333333 size=2 face=Verdana, Arial, Helvetica, sans-serif><strong> $titulo</strong></font></td> </tr> <tr> <td height=17 align=center valign=top><font color=#000000 size=2 face=Verdana, arial, helvetica, sans-serif>$imagem $texto</font></td> </tr> <tr> <td height=20 align=center valign=top><!--DWLayoutEmptyCell--> </td> </tr> <tr> <td height=13 valign=top><div align=center><a href=/mensagems><img src=../icone_voltar.gif alt=Ver_Todas_Mensagens width=92 height=21 border=0></a></div></td> </tr> </table> </div>"; } ?> |
OBS: Acabei de mudar, estava outro. FIZ CERTINHO?
Eu criei uma tabela "imagem"
e usei VARSHAR 200
Fiz certinho?
Ele diz que envia, mais quando vou ver na pasta de imagens não tem nada.
Edição feita por: gregorytg, 12/09/2004, 18:01.
#13
Posted 23/09/2017, 12:59
#14
Posted 11/02/2023, 21:17
Catabolic is a uniform where can i get fertomid
quetiapine minoxidil mk al 2 para barba Apollo is negotiating a deal with the United Steelworkers, which represents Cooper workers in the United States, after a U stromectol stock price
1 user(s) are reading this topic
0 membro(s), 1 visitante(s) e 0 membros anônimo(s)