Foros del Web » Programando para Internet » PHP »

Problema al exportar imágenes con PHP

Estas en el tema de Problema al exportar imágenes con PHP en el foro de PHP en Foros del Web. Hola. Tengo un formulario en el que los datos se guardan en un Excel. El problema ahora es que me pide el cliente que el ...
  #1 (permalink)  
Antiguo 28/01/2011, 11:06
 
Fecha de Ingreso: marzo-2008
Mensajes: 186
Antigüedad: 16 años, 1 mes
Puntos: 3
Problema al exportar imágenes con PHP

Hola.

Tengo un formulario en el que los datos se guardan en un Excel. El problema ahora es que me pide el cliente que el formulario incluya un campo que muestre la ruta de la imagen en el Excel junto con los demás datos, para así identificar a cada cliente. Tengo otro script dónde guardo las imágenes en un directorio.

Estoy buscando por san google y demás pero no doy con la solución, encima estoy muy limitado con php.

Pongo el código para facilitar la ayuda, éste es el código de inscripcion.php:

Código HTML:
Ver original
  1. <form action="apgform1.7.php" name="form1" method="post" id="contacto" class="cmxform" enctype="multipart/form-data">
  2. <input type="text" title="Campo Obligatorio" minlength="3" maxlength="50" name="nombre" id="nombre" class="required" />
  3. ...
  4. <input type="file" name="imagen" value="Examinar" />
  5. </form>

Para crear el Excel, utilizo la clase agpform1.7, encontré en google:

Código PHP:
Ver original
  1. <?php
  2. // Change this to the page you want the user to be redirected to after form is submitted (i.e. success.html and error.html)
  3.     $success = "confirmacion.php";
  4.     $error = "negacion.php";
  5. // Change this to the character(s) you want to be placed instead of line breaks(new line, enter, etc)
  6.     $lbChar = " ";  // default is a space, you may change it to whatever you want
  7.     // Don't change anything below this line       
  8.     // Determine if the form was sent through the GET methog or the POST method.
  9.     if($_POST){
  10.         $array = $_POST;
  11.     } else if($_GET){          
  12.         $array = $_GET;
  13.     } else {
  14.             die("You must Access this file through a form.");   // If someone accesses the file directly, it wont work :)
  15.     }  
  16.     //Check if the filename was sent through the form or not
  17.     if(!$array['filename']){
  18.         // if the filename wasnt sent through the form, it will become form.xls, you can change the default if you want.
  19.         $array['filename'] = "clientes.xls";    //Set the file to save the information in
  20.    
  21.     } else {
  22.         if(!(stristr($array['filename'],".xls"))){
  23.             $array['filename'] = $array['filename'] . ".xls";
  24.         }
  25.     }
  26.     // Define the tab and carriage return characters:
  27.     $tab = "\t";    //chr(9);
  28.     $cr = "\n";     //chr(13);
  29.     if($array){
  30.             // Make The Top row for the excel file and store it in the $header variable
  31.             $keys = array_keys($array);
  32.             foreach($keys as $key){
  33.                 if(strtolower($key) != 'filename' && strtolower($key) != 'title'){
  34.                     $header .= $key . $tab;
  35.                 }
  36.             }
  37.             $header .= $cr;
  38.             //Make the line with the contents to write to the excel file.
  39.             foreach($keys as $key){
  40.                 if(strtolower($key) != 'filename' && strtolower($key) != 'title'){
  41.                     $array[$key] = utf8_decode($array[$key]);//PARA RESPETAR LOS ACENTOS Y OTROS CARÁCTERES
  42.                     $array[$key] = str_replace("\n",$lbChar,$array[$key]);
  43.                     $array[$key] = preg_replace('/([\r\n])/e',"ord('$1')==10?'':''",$array[$key]);
  44.                     $array[$key] = str_replace("\\","",$array[$key]);
  45.                     $array[$key] = str_replace($tab, "    ", $array[$key]);
  46.                     $data .= $array[$key] . $tab ;
  47.                 }
  48.             }
  49.             $data .= $cr;
  50.             if (file_exists($array['filename'])) {
  51.                 $final_data = $data;        // If the file does exist, then only write the information the user sent
  52.             } else {
  53.                 $final_data = $header . $data;      // If file does not exist, write the header(first line in excel with titles) to the file
  54.             }
  55.             // open the file and write to it
  56.             $fp = fopen($array['filename'],"a"); // $fp is now the file pointer to file $array['filename']
  57.             if($fp){
  58.                 fwrite($fp,$final_data);    //Write information to the file
  59.                 fclose($fp);        // Close the file
  60.                 // Success
  61.                 header("Location: $success");
  62.             } else {
  63.                 // Error
  64.                 header("Location: $error");
  65.             }
  66.     }  
  67. ?>

El problema es que el Excel me genera todos los datos, salvo el campo con la ruta de la imagen que indique que se trata de una imagen.Si son tan amables, espero vuestra ayuda.

Gracias por anticipado.

Última edición por PSPforever; 28/01/2011 a las 12:31
  #2 (permalink)  
Antiguo 28/01/2011, 12:39
Avatar de LOCOHUESOS2  
Fecha de Ingreso: noviembre-2003
Ubicación: Cali - Colombia
Mensajes: 248
Antigüedad: 20 años, 5 meses
Puntos: 0
Respuesta: Problema al exportar imágenes con PHP

Jajaja

disculpa que cosas se les ocurre a los clientes algunos estan locos

bueno eso nunca lo habia pensado pero dejame decirte lo que se me ocurrio

abri excel 2007 seleccione una celda y le di en insertar imagen pero lo que se me ocurrio fue pegarle una URL http://www.luishrios.com/images/stor..._7046562_n.jpg y pues a mi me la bajo y mostro en la celda con esto te digo que investigues un poco de como lo podria hacer para cuando bajes los datos en el xls bajes ese URL de cada imagen que estaria en un registro por usuario en una DB

saludos espero te ayude en algo
__________________
No creas que eres superior a mi sin antes ver mi trabajo webcol.net
  #3 (permalink)  
Antiguo 03/02/2011, 03:51
 
Fecha de Ingreso: marzo-2008
Mensajes: 186
Antigüedad: 16 años, 1 mes
Puntos: 3
Respuesta: Problema al exportar imágenes con PHP

Gracias locohuesos, ya encontré la solución.

Guardo el nombre de la imagen en el excel, y las imágenes dentro de un directorio.

Etiquetas: Ninguno
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 04:15.