Jump to content


Photo

Upload E Visualização


  • Faça o login para participar
2 replies to this topic

#1 Existence

Existence

    Normal

  • Visitantes
  • PipPip
  • 82 posts
  • Sexo:Não informado

Posted 07/12/2004, 17:47

Galera tem um sistema de noticias bem básico q gostaria de adicionar imagem nele, se alguém puder ajudar agradeço, segue os códigos:


Inserir.php

Neste arquivo eu queria colocar o campo pra upload da imagem, um detalhe é que ele nao usa nenhum outro arquivo pra adicionar as informações ou seja é nele mesmo q tem as funções.

<?php require_once('../Connections/Noticias.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;   
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
  $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO noticias (titulo, texto, clicks) VALUES (%s, %s, %s)",
                      GetSQLValueString($HTTP_POST_VARS['titulo'], "text"),
                      GetSQLValueString($HTTP_POST_VARS['texto'], "text"),
                      GetSQLValueString($HTTP_POST_VARS['clicks'], "int"));

  mysql_select_db($database_Noticias, $Noticias);
  $Result1 = mysql_query($insertSQL, $Noticias) or die(mysql_error());
}
?>
<html>
<head>
<title>Documento sem t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
  <table align="center">
    <tr valign="baseline">
      <td nowrap align="right">Titulo:</td>
      <td><input type="text" name="titulo" value="" size="32">
      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right" valign="top">Texto:</td>
      <td>
        <textarea name="texto" cols="50" rows="5"></textarea>
      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Clicks:</td>
      <td><input type="text" name="clicks" value="" size="32">
      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td><div align="right">
        <input type="submit" value="Inserir not&iacute;cia">
      </div></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1">
</form>
<p>&nbsp;</p>
</body>
</html>



listar.php

Este aqui lista as manchetes ou seja os titulos das noticias, este nao ha necessidade de mudar nada, mas vou colocar pra alguem quiser aproveitar:

<?php require_once('../Connections/Noticias.php'); ?>
<?php
mysql_select_db($database_Noticias, $Noticias);
$query_listar_noticias = "SELECT * FROM noticias";
$listar_noticias = mysql_query($query_listar_noticias, $Noticias) or die(mysql_error());
$row_listar_noticias = mysql_fetch_assoc($listar_noticias);
$totalRows_listar_noticias = mysql_num_rows($listar_noticias);
?>
<html>
<head>
<title>Documento sem t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php do { ?>
<font size="2" face="Trebuchet MS">Titulo: <strong><?php echo $row_listar_noticias['titulo']; ?><br>
</strong>Clicks: <strong><?php echo $row_listar_noticias['clicks']; ?></strong><br>
<a href="exibir.php?id=<?php echo $row_listar_noticias['id']; ?>">Leia Mais +</a><br>
</font>
<hr width="100%" size="1" noshade>
<font size="2" face="Trebuchet MS"><br>
</font>
<?php } while ($row_listar_noticias = mysql_fetch_assoc($listar_noticias)); ?>
</body>
</html>
<?php
mysql_free_result($listar_noticias);
?>



exibir.php

É e neste arquivo eu queria q aparecesse a imagem q cadastrei no inicio juntamente com as informacoes da noticia:

<?php require_once('../Connections/Noticias.php'); ?>
<?php
$colname_exibir = "1";
if (isset($HTTP_GET_VARS['id'])) {
  $colname_exibir = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['id'] : addslashes($HTTP_GET_VARS['id']);
}
mysql_select_db($database_Noticias, $Noticias);
$query_exibir = sprintf("SELECT * FROM noticias WHERE id = %s", $colname_exibir);
$exibir = mysql_query($query_exibir, $Noticias) or die(mysql_error());
$row_exibir = mysql_fetch_assoc($exibir);
$totalRows_exibir = mysql_num_rows($exibir);
mysql_query("UPDATE noticias set clicks=clicks+1 where id='$_GET[id]'");
?>
<html>
<head>
<title>Documento sem t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<font size="2" face="Trebuchet MS"><strong>Titulo: </strong><?php echo $row_exibir['titulo']; ?><br>
<strong>Clicks:</strong> <?php echo $row_exibir['clicks']; ?><br>
<br>
<?php echo $row_exibir['texto']; ?></font>
</body>
</html>
<?php
mysql_free_result($exibir);
?>



Agora o sql da tabela:

CREATE TABLE `Noticias` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`titulo` VARCHAR(255),
`texto` TEXT,
`clicks` INT DEFAULT "0" NOT NULL
) TYPE = MYISAM
COMMENT = "tutorial";



Este script eu peguei de um artigo que foi postado por João Vagner no site do iMasters, caso alguém quer vê-lo Clique aqui (direitos autorais né).

Aguardo ajuda, obrigado.
Existence Webstudio
Aqui é o seu lugar, exista!


→ Antes de postar, use a busca-> <- Link para a busca ->
→ Para não cometer erros, leia as regras do fórum

→ Mais info sobre eu ←
Nome: Juliano Tavares
E-mail: juliano@existence.com.br
Conhecimentos: Photoshop, Macromedia Studio, PHP/MySql
→ Colunista Photoshop - DevBrasil - acesse já!

#2 Felipe Pena

Felipe Pena

    O temor do Senhor é o princípio da sabedoria

  • Ex-Admins
  • 6441 posts
  • Sexo:Masculino

Posted 08/12/2004, 03:26

Ae rapaz..

Só você juntar:

<?

echo '
<form method="post" enctype="multipart/form-data" action="'.$editFormAction.'">
Foto: <input type="file" name="foto"><br />
<input type="submit" name="submit" value=" ENVIAR "></form>
';

?>


//Validando

<?
$foto_name = $_FILES['foto']['name'];
$foto_tmp = $_FILES['foto']['tmp_name'];
$foto_type = $_FILES['foto'['type'];

if ($foto_name!="") {
  if (eregi("(gif|bmp|jpeg|jpg|png|psd)", substr($foto_name, -3))) {
    //enviando para a pasta
    move_uploaded_file($foto_tmp, "pasta/".$foto_name);

    //endereço da foto no servidor
    $end = "www.site.com.br/pasta/".$foto_name;
    mysql_query("INSERT INTO Noticias (foto) VALUES ('$end')")
      or die (mysql_error());

  } else {
    echo "Extensão de foto inválida!";
}
?>


Felipe Pena
[...] ó terra, terra, terra; ouve a palavra do Senhor. — Jeremias 22:29

#3 Existence

Existence

    Normal

  • Visitantes
  • PipPip
  • 82 posts
  • Sexo:Não informado

Posted 08/12/2004, 11:21

tentei mas nao deu certo amigo, vlw amigo, se alguém puder adaptar isso ai pra mim e postar como fez pra funcionar agradeço.


obrigado
Existence Webstudio
Aqui é o seu lugar, exista!


→ Antes de postar, use a busca-> <- Link para a busca ->
→ Para não cometer erros, leia as regras do fórum

→ Mais info sobre eu ←
Nome: Juliano Tavares
E-mail: juliano@existence.com.br
Conhecimentos: Photoshop, Macromedia Studio, PHP/MySql
→ Colunista Photoshop - DevBrasil - acesse já!




0 user(s) are reading this topic

0 membro(s), 0 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq