Foros del Web » Programando para Internet » PHP »

upload multiples imagenes php js

Estas en el tema de upload multiples imagenes php js en el foro de PHP en Foros del Web. compañeros tengo el siguiente problema. Necesito subir varias imagenes al mismo tiempo a un servidor cuando se registre un paciente en una bd. hasta ahi ...
  #1 (permalink)  
Antiguo 15/02/2012, 10:29
 
Fecha de Ingreso: diciembre-2007
Mensajes: 427
Antigüedad: 16 años, 4 meses
Puntos: 35
upload multiples imagenes php js

compañeros tengo el siguiente problema.
Necesito subir varias imagenes al mismo tiempo a un servidor cuando se registre un paciente en una bd. hasta ahi me funciona. Pero tambien que cuando yo voy a actualizar ese paciente pueda agregar mas imagenes de el. Ese es el problema para registrar funciona pero para actualizar no.

Si alguien me puede ayudar se lo agradeceria enormente por q la verdad no se donde esta la falla si les parece muy largo el post solo vean los dos primeros formularios a ver si me pueden decir por q en uno si llega la info de los files y en el otro no.
Estos son los scripts que utilizo.
Este formulario para registrar y subir multiples imagenes:
Código HTML:
<center>
<h1>Registre aqui su Paciente</h1>
 <form action='<?php $mivar = "paciente";
  $url = $_SERVER['SCRIPT_NAME'] . "?evento=$mivar";
  echo $url;?>'method="post" enctype="multipart/form-data" name="form1">
  <table border="1" width="328" bgcolor="#FFFFCC">
<tr>
<td width="126">Cedula:</td>
<td width="186"><input type="text" name="cedula" width="100" /></td></tr>
<tr><td>Nombre: </td><td><input type="text" name="nombre" width="100"/></td></tr>
<tr><td>Fecha Nacimiento:</td><td>

<input type="text" name="fecha_nacimiento"id="fecha" readonly="readonly"  width="100"/><input name="popcal" onClick="if(this.blur)this.blur();var fm=this.form1;if(self.gfPop)gfPop.fPopCalendar(document.form1.fecha);" value="..." type="button"></td></tr>
<tr><td>Telefono: </td><td><input type="text" name="telefono" maxlength="10"/>

</td></tr>
<tr><td>Subir Imagenes:</td><td> <a href="#" onclick="addField()" accesskey="5">A&ntilde;adir Imagen</a></td>
               <tr><td colspan="2"><div id="files"></div></td></tr><tr><td colspan="2" align="center"><input type="submit" name="bot_Registrar_Paciente" value="Enviar"  /></td></tr></table></form></center>
                <iframe name="gToday:normal:agenda.js" id="gToday:normal:agenda.js" src="calendar/ipopeng.htm" style="visibility: visible; z-index: 999; position: absolute; top: -500px; left: -500px;" frameborder="0" height="189" scrolling="no" width="174"></iframe>
              
Este me funciona perfectamente y me llegan los valores asociados en el vector $_Files['archivos'] y este de abajo es casi el mismo formulario pero con php
y no me funciona para agragar mas imagenes.

Código PHP:
public function Mostrar_Para_Actualizar($cedula){
    
$mostrar="";
    
$sql="SELECT * From Paciente where Paciente_Cedula=".$cedula.";";
    
$sql2="SELECT Paciente_Imagenes_Id, Paciente_Imagenes_Paciente, Paciente_Imagenes_Nombre
FROM paciente_imagenes
WHERE Paciente_Imagenes_Paciente ="
.$cedula."";
    
$this->conexion=new Mysql_conection();
    
$this->conexion->conectar();
    
$rst=$this->conexion->ejecutar_sql($sql);
    
$rst2=$this->conexion->ejecutar_sql($sql2);
    
$num=mysql_num_rows($rst2);
        if(
mysql_num_rows($rst)>0){
        
$row=mysql_fetch_array($rst);
        
$edad=$this->Calcular_Edad($row['Paciente_Fecha_Nacimiento']); 
        
$mostrar.="<center>
<table border='1' width='328' bgcolor='#FFFFCC'>
<form action=$_SERVER[SCRIPT_NAME] method='post' enctype='multipart/form-data' name='form_ac' >
<tr><td>ID:</td><td>"
.$row['Paciente_Id']."</td></tr>
<tr><td width='116'>Nombre:</td>
<td><input type='text' name='nombre' width='100' value='"
.$row['Paciente_Nombre']."' /></td></tr>
<tr><td>Cedula: </td><td><input type='text' name='cedula' width='100' value='"
.$row['Paciente_Cedula']."' /></td></tr>
<tr><td>Fecha Naci:</td><td><input type='text' name='fecha_nacimiento' id='fecha' readonly='readonly' value='"
.$row['Paciente_Fecha_Nacimiento']."'  width='100'/><input name='popcal' onClick='if(this.blur)this.blur();var fm=this.form_ac;if(self.gfPop)gfPop.fPopCalendar(document.form_ac.fecha);' value='edit' type='button'></td></tr>
<tr><td>Edad:</td><td>"
.$edad."</td></tr>
<tr><td>Telefono: </td><td><input type='text' name='telefono' width='100' value='"
.$row['Paciente_Telefono']."' maxlength='10' /></td></tr>
<tr><td colspan='2'>Imagenes</td></tr>"
;
if(
$num>0){
while(
$row2=mysql_fetch_array($rst2)){
$mostrar.="<tr><td><a href='imgpacientes/".$row2['Paciente_Imagenes_Nombre']."' > ver ".$row2['Paciente_Imagenes_Nombre']." </a></td>
<td><a href='?evento=bpaciente&value="
.$row2['Paciente_Imagenes_Id']."&accion=deleteimg' ><img title='Eliminar' src='icon/delete2.png' height='25' width='25' onclick=\"return confirm('Realmente Desea Eliminar?')\"  /> </a></td></tr>";}
}
$mostrar.='<tr><td>Subir Imagenes:</td><td>   <a href="#" onclick="addField()" accesskey="5">A&ntilde;adir Imagen</a></td>
               <tr><td colspan="2"> <dd><div id="files"></div></dd></td></tr>'
;
               
               
$mostrar.="<tr><td><input name='bot_update' type='submit' value='update' height='10' width='10' ></td><td><input name='bot_delete' type='submit' value='delete' onclick=\"return confirm('Realmente Desea Eliminar?')\"  height='10' width='10' ></td></tr><input type='hidden' name='id' value='".$row['Paciente_Id']."' /></form></table>
</center><br> <iframe name='gToday:normal:agenda.js' id='gToday:normal:agenda.js' src='calendar/ipopeng.htm' style='visibility: visible; z-index: 999; position: absolute; top: -500px; left: -500px;' frameborder='0' height='189' scrolling='no' width='174'></iframe>"
;
        }
        else{
        
$mostrar="Su busqueda no encontro resultados";
        }

    
$this->conexion->desconectar($rst);
    return 
$mostrar;    
    } 
este es el forumlario que me arroja desde la base de datos para actualizar la parte <div id="files"> me crea los campos tipo files cada vez que le doy al enlace añadir imagenes. Enviando desde este formulario no se llena el vector $_Files['archivos'] el cual tiene las imagenes a subir
Les agradeceria enormente su ayuda pues me parece q estan iguales y uno el de actualizar no me funciona.

Este es el script js para crear los files dinamicamente
Cita:
// JavaScript Document

var numero = 1;

// Funciones comunes
c= function (tag) { // Crea un elemento
return document.createElement(tag);
}
d = function (id) { // Retorna un elemento en base al id
return document.getElementById(id);
}
e = function (evt) { // Retorna el evento
return (!evt) ? event : evt;
}
f = function (evt) { // Retorna el objeto que genera el evento
return evt.srcElement ? evt.srcElement : evt.target;
}

addField = function () {
container = d('files');

span = c('SPAN');
span.className = 'File';
span.id = 'File' + (++numero);

field = c('INPUT');
field.name = 'archivos[]';
field.type = 'File';

a = c('A');
a.name = span.id;
a.href = '#';
a.onclick = removeField;
a.innerHTML = 'Quitar';

span.appendChild(field);
span.appendChild(a);
container.appendChild(span);
}
removeField = function (evt) {
lnk = f(e(evt));
span = d(lnk.name);
span.parentNode.removeChild(span);
}
Y esta es la pagina principar que procesa todo
Código PHP:
if(isset($_GET['evento']) and $_GET['evento']=="fregistrar_paciente"){

ob_start();
require_once( 
"Form_Registrar_Paciente.html" );
$mostrar .= ob_get_clean();  
$mostrar.="<br>";
}
if(isset(
$_POST['bot_Registrar_Paciente'])){
echo 
"entra registrar";
$p=new Class_Paciente();
$p->set_Cedula($_POST['cedula']);
$p->set_nombre($_POST['nombre']);
$p->set_Fecha_Nacimiento($_POST['fecha_nacimiento']);
$p->set_Telefono($_POST['telefono']);
if(
$p->Existe_Id(1)){
$id=$p->obtener_Id_Mayor();
$id++;
$p->set_Id($id);
}
else{
$p->set_Id(1);
}
 if (isset (
$_FILES['archivos'])) {//if files
  
$anombres=array();
 
  foreach  (
$_FILES["archivos"]["error"] as $key => $error) {
  
   if (
$error == UPLOAD_ERR_OK) {
   echo 
"<h1>entra<br>";
   
//$anombres[]=$_FILES["archivos"]["name"][$key];
   
$tmp_name $_FILES["archivos"]["tmp_name"][$key];
   
//$name = $_FILES["archivos"]["name"][$key];
   
$ruta='imgpacientes/p.jpg';
   
//$name = uniqid('bc') . '_' . $name;
   
$ext strstr($_FILES['archivos']['name'][$key],'.'); 
   
   
$name=$_POST['cedula']."_".$key.$ext;
   
$anombres[]=$name;
    
move_uploaded_file($tmp_name"imgpacientes/$name");
 
// $p->Upload_Basico($_FILES['archivos'],$ruta);
   
}
  }

 
$p->set_Imagenes($anombres);
 }
//end if files
$p->Registrar_Paciente();
}
if(isset(
$_POST['bot_update'])){
echo 
"entra act";
$p=new Class_Paciente();
$p->set_Cedula($_POST['cedula']);
$p->set_nombre($_POST['nombre']);
$p->set_Fecha_Nacimiento($_POST['fecha_nacimiento']);
$p->set_Telefono($_POST['telefono']);
echo 
"<br>aqui salta";

if (isset (
$_FILES['archivos'])) {//if files
  
$anombres=array();
 echo 
"<h1>archivos</h1>";
  foreach  (
$_FILES["archivos"]["error"] as $key => $error) {
  
   if (
$error == UPLOAD_ERR_OK) {
   echo 
"<h1>entra<br>";
   
//$anombres[]=$_FILES["archivos"]["name"][$key];
   
$tmp_name $_FILES["archivos"]["tmp_name"][$key];
   
//$name = $_FILES["archivos"]["name"][$key];
//   $ruta='imgpacientes/p.jpg';
   //$name = uniqid('bc') . '_' . $name;
   
$ext strstr($_FILES['archivos']['name'][$key],'.'); 
   
   
$name=$_POST['cedula']."_".$key.$ext;
   
$anombres[]=$name;
    
move_uploaded_file($tmp_name"imgpacientes/$name");
 
// $p->Upload_Basico($_FILES['archivos'],$ruta);
   
}
  }

 
$p->set_Imagenes($anombres);
 }
//end if files
$p->Update_Paciente($_POST['id']);
}

require_once(
'Administrador.html'); 
  #2 (permalink)  
Antiguo 15/02/2012, 19:39
 
Fecha de Ingreso: diciembre-2007
Mensajes: 427
Antigüedad: 16 años, 4 meses
Puntos: 35
Respuesta: upload multiples imagenes php js

Bueno lo probe con un jquery muy popula jquerymultifile.js y seguia el mismo problema
pero lo pude solucionar creando una pagina html con el formulario para actualizar y los datos.
Y llamandola desde el index mediante
ob_start();
require_once( "Form_Update_Paciente.html" );
$mostrar .= ob_get_clean();

Salu2.

Etiquetas: formulario, html, imagenes, js, multiples, mysql, sql, upload
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 14:25.