Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] Sistema noticia y foto

Estas en el tema de Sistema noticia y foto en el foro de PHP en Foros del Web. Bueno tarde, quiero como sistema notica imagenes subir carpeta y php y sql solo foto.png y jpg codigo Código PHP: <?php  require_once( 'Connections/conexion.php' );  ?> ...
  #1 (permalink)  
Antiguo 05/04/2013, 11:27
 
Fecha de Ingreso: abril-2013
Mensajes: 39
Antigüedad: 11 años
Puntos: 0
Sistema noticia y foto

Bueno tarde, quiero como sistema notica imagenes subir carpeta y php y sql solo foto.png y jpg
codigo
Código PHP:
<?php require_once('Connections/conexion.php'); ?>
<?php
if (!isset($_SESSION)) {
  
session_start();
}
$MM_authorizedUsers "";
$MM_donotCheckaccess "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers$strGroups$UserName$UserGroup) { 
  
// For security, start by assuming the visitor is NOT authorized. 
  
$isValid False

  
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  
if (!empty($UserName)) { 
    
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    
$arrUsers Explode(","$strUsers); 
    
$arrGroups Explode(","$strGroups); 
    if (
in_array($UserName$arrUsers)) { 
      
$isValid true
    } 
    
// Or, you may restrict access to only certain users based on their username. 
    
if (in_array($UserGroup$arrGroups)) { 
      
$isValid true
    } 
    if ((
$strUsers == "") && true) { 
      
$isValid true
    } 
  } 
  return 
$isValid
}

$MM_restrictGoTo "user/login.php";
if (!((isset(
$_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers$_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  
$MM_qsChar "?";
  
$MM_referrer $_SERVER['PHP_SELF'];
  if (
strpos($MM_restrictGoTo"?")) $MM_qsChar "&";
  if (isset(
$_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0
  
$MM_referrer .= "?" $_SERVER['QUERY_STRING'];
  
$MM_restrictGoTo $MM_restrictGoTo$MM_qsChar "accesscheck=" urlencode($MM_referrer);
  
header("Location: "$MM_restrictGoTo); 
  exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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 $_SERVER['PHP_SELF'];
if (isset(
$_SERVER['QUERY_STRING'])) {
  
$editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO Noticia (Temas, Foto, text, Video, Nombre, Usuarios) VALUES (%s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['Temas'], "text"),
                       
GetSQLValueString($_POST['Foto'], "text"),
                       
GetSQLValueString($_POST['text'], "text"),
                       
GetSQLValueString($_POST['Video'], "text"),
                       
GetSQLValueString($_POST['Nombre'], "text"),
                       
GetSQLValueString($_POST['Usuarios'], "int"));

  
mysql_select_db($database_conexion$conexion);
  
$Result1 mysql_query($insertSQL$conexion) or die(mysql_error());
}

$colname_Recordset1 "-1";
if (isset(
$_SESSION['MM_Username'])) {
  
$colname_Recordset1 $_SESSION['MM_Username'];
}
mysql_select_db($database_conexion$conexion);
$query_Recordset1 sprintf("SELECT `id`, Nombre, Apellido, Usuarios FROM usuario WHERE Usuarios = %s"GetSQLValueString($colname_Recordset1"text"));
$Recordset1 mysql_query($query_Recordset1$conexion) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Cocina Sorda</title>
<link href="css/themas.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="contenedor">
  <div id="cabecera"><img src="images/cocina1.png" width="172" height="190" /></div>
  <div class="menu"><a href="index.php">INICIO</a> l <a href="gente.php">GENTE</a> l <a href="user/cuenta.php">CUENTA</a> l <a href="contacto.php">CONTACTO</a></div>
  <?php include("menu.php"); ?>
  <div class="contenidos">
  
    <form action="<?php echo $editFormAction?>" method="post" name="form1" id="form1" enctype="multipart/form-data">
      <table align="center">
        <tr valign="baseline">
          <td height="32">Titulo<br/><input type="text" name="Temas" value="" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td>Foto<br/><input type="file" name="file" id="file"></td>
        </tr>
        <tr valign="baseline">
          <td>Escribe<br/><textarea name="text" cols="60" rows="10">text…..</textarea></td>
        </tr>
        <tr valign="baseline">
          <td>http://youtu.be/<input type="text" name="Video" value="" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td><input type="submit" value="Insertar registro" /></td>
        </tr>
      </table>
      <input name="Nombre" type="hidden" value="<?php echo $row_Recordset1['Nombre']; ?> <?php echo $row_Recordset1['Apellido']; ?>" />
      <input type="hidden" name="Usuarios" value="<?php echo $row_Recordset1['id']; ?>" />
      <input type="hidden" name="Foto" value="<?php echo $_FILES["file"]["name"]; ?>" />
      <input type="hidden" name="MM_insert" value="form1" />
    </form>
  </div>
  <?php include("pie.php"); ?>
</div>
</body>
</html>
<?php
mysql_free_result
($Recordset1);
?>
  #2 (permalink)  
Antiguo 05/04/2013, 11:43
Avatar de maycolalvarez
Colaborador
 
Fecha de Ingreso: julio-2008
Ubicación: Caracas
Mensajes: 12.120
Antigüedad: 15 años, 8 meses
Puntos: 1532
Respuesta: Sistema noticia y foto

no veo que en ninguna parte gestiones la subida del archivo, puedes buscar un tutorial sencillo de php upload files para orientarte
__________________
¡Por favor!: usa el highlight para mostrar código
El que busca, encuentra...
  #3 (permalink)  
Antiguo 05/04/2013, 11:46
 
Fecha de Ingreso: abril-2013
Mensajes: 39
Antigüedad: 11 años
Puntos: 0
Respuesta: Sistema noticia y foto

pero noticia y foto la subida del archivo formulario mysql y php Insertar registro
  #4 (permalink)  
Antiguo 05/04/2013, 12:28
Avatar de maycolalvarez
Colaborador
 
Fecha de Ingreso: julio-2008
Ubicación: Caracas
Mensajes: 12.120
Antigüedad: 15 años, 8 meses
Puntos: 1532
Respuesta: Sistema noticia y foto

Cita:
Iniciado por camilomascarell1987 Ver Mensaje
pero noticia y foto la subida del archivo formulario mysql y php Insertar registro
no se entiende lo que escribes.

de igual forma, cuando haces el INSERT en la base de datos, llamas a $_POST['foto'], $_POST NO aplica para los archivos, debes usar el arreglo $_FILES

consulte el manual de php, upload de archivos: http://www.php.net/manual/es/feature...ost-method.php

otro punto es que quieras almacenar el binario de la foto en un campo BLOB de la base de datos: para esto hay tutoriales específicos, pero yo no lo recomiendo, lo mejor es mover el archivo a un directorio específico y guardar en el campo de la base de datos el path hacia el archivo.
__________________
¡Por favor!: usa el highlight para mostrar código
El que busca, encuentra...
  #5 (permalink)  
Antiguo 05/04/2013, 12:57
 
Fecha de Ingreso: abril-2013
Mensajes: 39
Antigüedad: 11 años
Puntos: 0
Respuesta: Sistema noticia y foto

$_files es muy error
Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in /Applications/XAMPP/xamppfiles/htdocs/cocinasorda/Connections/conexion.php on line 23
Column 'Foto' cannot be null
Código PHP:
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO Noticia (user_id, Foto, Video, Temas, text, Nombre) VALUES (%s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['user_id'], "text"),
                       
GetSQLValueString($_FILES['Foto'], "text"),
                       
GetSQLValueString($_POST['Video'], "text"),
                       
GetSQLValueString($_POST['Temas'], "text"),
                       
GetSQLValueString($_POST['text'], "text"),
                       
GetSQLValueString($_POST['Nombre'], "text")); 
Código PHP:
<form action="<?php echo $editFormAction?>" method="post" name="form1" id="form1" enctype="multipart/form-data">
      <table align="center">
        <tr valign="baseline">
          <td height="32">Titulo<br/><input type="text" name="Temas" value="" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td>Foto<br/><input type="file" name="Foto" id="Foto"></td>
        </tr>
        <tr valign="baseline">
          <td>Escribe<br/><textarea name="text" cols="60" rows="10">text…..</textarea></td>
        </tr>
        <tr valign="baseline">
          <td>http://youtu.be/<input type="text" name="Video" value="" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td><input type="submit" value="Insertar registro" /></td>
        </tr>
      </table>
      <input name="Nombre" type="hidden" value="<?php echo $row_Recordset1['Nombre']; ?> <?php echo $row_Recordset1['Apellido']; ?>" />
      <input type="hidden" name="user_id" value="<?php echo $row_Recordset1['id']; ?>" />
      <input type="hidden" name="MM_insert" value="form1" />
    </form>
  #6 (permalink)  
Antiguo 05/04/2013, 14:42
Avatar de maycolalvarez
Colaborador
 
Fecha de Ingreso: julio-2008
Ubicación: Caracas
Mensajes: 12.120
Antigüedad: 15 años, 8 meses
Puntos: 1532
Respuesta: Sistema noticia y foto

No puedes usar mysql_real_escape_string() con $_FILES['foto'] ya que es un arreglo, quizás con $_FILES['foto']['tmp_name']

y como lo anterior lo devuelve vacío, te dá error NULL porque el campo es requerido en DB

además el input file se llama file, entonces quedaría:

Código PHP:
Ver original
  1. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  2.   $insertSQL = sprintf("INSERT INTO Noticia (user_id, Foto, Video, Temas, text, Nombre) VALUES (%s, %s, %s, %s, %s, %s)",
  3.                        GetSQLValueString($_POST['user_id'], "text"),
  4.                        GetSQLValueString($_FILES['file']['tmp_name'], "text"),
  5.                        GetSQLValueString($_POST['Video'], "text"),
  6.                        GetSQLValueString($_POST['Temas'], "text"),
  7.                        GetSQLValueString($_POST['text'], "text"),
  8.                        GetSQLValueString($_POST['Nombre'], "text"));

por otro lado, si no mueves el archivo de la foto, el OS lo eliminará porque está en la carpeta temporal.
__________________
¡Por favor!: usa el highlight para mostrar código
El que busca, encuentra...
  #7 (permalink)  
Antiguo 05/04/2013, 15:35
 
Fecha de Ingreso: abril-2013
Mensajes: 39
Antigüedad: 11 años
Puntos: 0
Respuesta: Sistema noticia y foto

muchas gracias
  #8 (permalink)  
Antiguo 08/04/2013, 10:12
 
Fecha de Ingreso: abril-2013
Mensajes: 39
Antigüedad: 11 años
Puntos: 0
Respuesta: Sistema noticia y foto

oye hacer falta subir carpeta $_FILES file_uploads donde?

Etiquetas: foto, html, mysql, noticia, registro, select, sistema, sql, usuarios
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 10:18.