Foros del Web » Programando para Internet » PHP »

formulario subir multiples de imagenes con php mysql

Estas en el tema de formulario subir multiples de imagenes con php mysql en el foro de PHP en Foros del Web. como haces subir multiples imagenes solo mysql? Código PHP: <form action=" <?php  echo  $editFormAction ;  ?> " name="fotonuevo" method="POST" enctype="multipart/form-data" id="fotonuevo">   <label for="imagenes">Imagenes:</label>   <input name="imagenes" type="file" multiple id="imagenes">   <input type="submit" name="submit" id="submit" value="Enviar">   <input type="hidden" name="MM_insert" value="fotonuevo"> </form> mysql codigo: Código PHP: ...
  #1 (permalink)  
Antiguo 09/05/2015, 06:00
 
Fecha de Ingreso: abril-2013
Mensajes: 39
Antigüedad: 11 años
Puntos: 0
Mensaje formulario subir multiples de imagenes con php mysql

como haces subir multiples imagenes solo mysql?
Código PHP:
<form action="<?php echo $editFormAction?>" name="fotonuevo" method="POST" enctype="multipart/form-data" id="fotonuevo">
  <label for="imagenes">Imagenes:</label>
  <input name="imagenes" type="file" multiple id="imagenes">
  <input type="submit" name="submit" id="submit" value="Enviar">
  <input type="hidden" name="MM_insert" value="fotonuevo">
</form>
mysql codigo:
Código PHP:
<?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"] == "fotonuevo")) {
  
$insertSQL sprintf("INSERT INTO foto (imagenes) VALUES (%s)",
                       
GetSQLValueString($_FILES['imagenes']['name'], "text"));
                       
if (isset(
$_FILES['imagenes'])){
    
// Hacemos una condicion en la que solo permitiremos que se suban imagenes y que sean menores a 20 KB
    
if ((($_FILES["imagenes"]["type"] == "image/gif") || 
    (
$_FILES["imagenes"]["type"] == "image/jpeg") || 
    (
$_FILES["imagenes"]["type"] == "image/png") ||
    (
$_FILES["imagenes"]["type"] == "image/pjpeg")) && 
    (
$_FILES["imagenes"]["size"] < 2000000)) {
    
    
//Si es que hubo un error en la subida, mostrarlo, de la variable $_FILES podemos extraer el valor de [error], que almacena un valor booleano (1 o 0).
      
if ($_FILES["imagenes"]["error"] > 0) {
        echo 
$_FILES["imagenes"]["error"] . "<br />";
      } else {
          
// Si no hubo ningun error, hacemos otra condicion para asegurarnos que el archivo no sea repetido
          
if (file_exists("../fotografico/foto/" $_FILES["imagenes"]["name"])) {
            echo 
$_FILES["imagenes"]["name"] . " ya existe. ";
          } else {
           
// Si no es un archivo repetido y no hubo ningun error, procedemos a subir a la carpeta /archivos, seguido de eso mostramos la imagen subida
            
move_uploaded_file($_FILES["imagenes"]["tmp_name"],
            
"../fotografico/foto/" $_FILES["imagenes"]["name"]);
          }
      }
    } else {
        
// Si el usuario intenta subir algo que no es una imagen o una imagen que pesa mas de 20 KB mostramos este mensaje
    
}
}

  
mysql_select_db($database_digitalflash$digitalflash);
  
$Result1 mysql_query($insertSQL$digitalflash) or die(mysql_error());

  
$insertGoTo "foto_index.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));
}

mysql_select_db($database_digitalflash$digitalflash);
$query_admin "SELECT * FROM `admin`";
$admin mysql_query($query_admin$digitalflash) or die(mysql_error());
$row_admin mysql_fetch_assoc($admin);
$totalRows_admin mysql_num_rows($admin);

mysql_select_db($database_digitalflash$digitalflash);
$query_fotonuevo "SELECT * FROM foto";
$fotonuevo mysql_query($query_fotonuevo$digitalflash) or die(mysql_error());
$row_fotonuevo mysql_fetch_assoc($fotonuevo);
$totalRows_fotonuevo mysql_num_rows($fotonuevo);
?>
  #2 (permalink)  
Antiguo 09/05/2015, 12:41
Avatar de enlinea777  
Fecha de Ingreso: mayo-2008
Ubicación: frente al pc
Mensajes: 1.830
Antigüedad: 15 años, 11 meses
Puntos: 127
Respuesta: formulario subir multiples de imagenes con php mysql

asi envias varios datos
Código HTML:
Ver original
  1. <form action="" name="fotonuevo" method="POST" enctype="multipart/form-data" id="fotonuevo">
  2.   <label for="imagenes">Imagenes:</label>
  3.   <input name="imagenes[]" type="file" multiple id="imagenes">
  4.   <input type="submit" name="submit" id="submit" value="Enviar">
  5.   <input type="hidden" name="MM_insert" value="fotonuevo">
  6. </form>

ahora php recibe un array en imagenes con la cantidad de imagenes seleccionadas
  #3 (permalink)  
Antiguo 09/05/2015, 16:20
 
Fecha de Ingreso: abril-2013
Mensajes: 39
Antigüedad: 11 años
Puntos: 0
Respuesta: formulario subir multiples de imagenes con php mysql

Código HTML:
Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in /Applications/XAMPP/xamppfiles/htdocs/digitalflash/admin/foto_nuevo.php on line 83
Column 'imagenes' cannot be null
  #4 (permalink)  
Antiguo 09/05/2015, 19:32
Avatar de NueveReinas  
Fecha de Ingreso: septiembre-2013
Ubicación: No tan Buenos Aires
Mensajes: 1.101
Antigüedad: 10 años, 7 meses
Puntos: 145
Respuesta: formulario subir multiples de imagenes con php mysql

Cita:
Iniciado por camilomascarell1987 Ver Mensaje
Código HTML:
Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in /Applications/XAMPP/xamppfiles/htdocs/digitalflash/admin/foto_nuevo.php on line 83
Column 'imagenes' cannot be null
Para empezar, recomiendo que uses la versión MySQLi de ese método: http://php.net/manual/es/mysqli.real-escape-string.php

Por otra parte, quizá el error se deba a que la variable introducida no sea un string.
__________________
¿Te sirvió la respuesta? Deja un +1
  #5 (permalink)  
Antiguo 09/05/2015, 22:00
Avatar de gnzsoloyo
Moderador criollo
 
Fecha de Ingreso: noviembre-2007
Ubicación: Actualmente en Buenos Aires (el enemigo ancestral)
Mensajes: 23.324
Antigüedad: 16 años, 4 meses
Puntos: 2658
Respuesta: formulario subir multiples de imagenes con php mysql

Cita:
Iniciado por camilomascarell1987 Ver Mensaje
Código HTML:
Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in /Applications/XAMPP/xamppfiles/htdocs/digitalflash/admin/foto_nuevo.php on line 83
Column 'imagenes' cannot be null
Literalmente, el mensaje indica que estas insertando un NULL en el campo "imágenes", lo que indicaría que tu script no está recibiendo nada...
Deberías verificar que llega ANTES de crear ese INSERT.
__________________
¿A quién le enseñan sus aciertos?, si yo aprendo de mis errores constantemente...
"El problema es la interfase silla-teclado." (Gillermo Luque)
  #6 (permalink)  
Antiguo 10/05/2015, 12:31
 
Fecha de Ingreso: abril-2013
Mensajes: 39
Antigüedad: 11 años
Puntos: 0
Respuesta: formulario subir multiples de imagenes con php mysql

Mysql es muy problemas paso?
Código HTML:
Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in /Applications/XAMPP/xamppfiles/htdocs/digitalflash/admin/foto_nuevo.php on line 83
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1
Código PHP:
<?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 "'" "INSERT";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "INSERT";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "INSERT";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "INSERT";
      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"] == "fotonuevo")) {
  
$insertSQL sprintf("INSERT INTO foto (imagenes) VALUES (%s)",
                       
GetSQLValueString($_FILES['imagenes']['name'], "text"));
                       
if (isset(
$_FILES['imagenes'])){
    
// Hacemos una condicion en la que solo permitiremos que se suban imagenes y que sean menores a 20 KB
    
if ((($_FILES["imagenes"]["type"] == "image/gif") || 
    (
$_FILES["imagenes"]["type"] == "image/jpeg") || 
    (
$_FILES["imagenes"]["type"] == "image/png") ||
    (
$_FILES["imagenes"]["type"] == "image/pjpeg")) && 
    (
$_FILES["imagenes"]["size"] < 2000000)) {
    
    
//Si es que hubo un error en la subida, mostrarlo, de la variable $_FILES podemos extraer el valor de [error], que almacena un valor booleano (1 o 0).
      
if ($_FILES["imagenes"]["error"] > 0) {
        echo 
$_FILES["imagenes"]["error"] . "<br />";
      } else {
          
// Si no hubo ningun error, hacemos otra condicion para asegurarnos que el archivo no sea repetido
          
if (file_exists("../fotografico/foto/" $_FILES["imagenes"]["name"])) {
            echo 
$_FILES["imagenes"]["name"] . " ya existe. ";
          } else {
           
// Si no es un archivo repetido y no hubo ningun error, procedemos a subir a la carpeta /archivos, seguido de eso mostramos la imagen subida
            
move_uploaded_file($_FILES["imagenes"]["tmp_name"],
            
"../fotografico/foto/" $_FILES["imagenes"]["name"]);
          }
      }
    } else {
        
// Si el usuario intenta subir algo que no es una imagen o una imagen que pesa mas de 20 KB mostramos este mensaje
    
}
}

  
mysql_select_db($database_digitalflash$digitalflash);
  
$Result1 mysql_query($insertSQL$digitalflash) or die(mysql_error());

  
$insertGoTo "foto_index.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));
}

mysql_select_db($database_digitalflash$digitalflash);
$query_admin "SELECT * FROM `admin`";
$admin mysql_query($query_admin$digitalflash) or die(mysql_error());
$row_admin mysql_fetch_assoc($admin);
$totalRows_admin mysql_num_rows($admin);

mysql_select_db($database_digitalflash$digitalflash);
$query_fotonuevo "SELECT * FROM foto";
$fotonuevo mysql_query($query_fotonuevo$digitalflash) or die(mysql_error());
$row_fotonuevo mysql_fetch_assoc($fotonuevo);
$totalRows_fotonuevo mysql_num_rows($fotonuevo);
?>
  #7 (permalink)  
Antiguo 11/05/2015, 02:46
 
Fecha de Ingreso: abril-2013
Mensajes: 39
Antigüedad: 11 años
Puntos: 0
Respuesta: formulario subir multiples de imagenes con php mysql

POR FAVOR TU Y YO AYUDA PHP ES MUY PROBLEMAS, ESTOY ROPMRE MUCHOS VECES
Código PHP:
  $theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); 

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

  #8 (permalink)  
Antiguo 11/05/2015, 06:56
Avatar de enlinea777  
Fecha de Ingreso: mayo-2008
Ubicación: frente al pc
Mensajes: 1.830
Antigüedad: 15 años, 11 meses
Puntos: 127
Respuesta: formulario subir multiples de imagenes con php mysql

Al parecer estas usando dreamweaver para hacer todo y no comprendes lo que haces.
no uses dreamweaver para que escriba tu codigo, recuerda que ahora recibes un array de archivos y no una sola variable

Etiquetas: formulario, html, imagenes, multiples, mysql, select, sql, variable
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 02:30.