Foros del Web » Programando para Internet » PHP »

subir archivos por partes

Estas en el tema de subir archivos por partes en el foro de PHP en Foros del Web. hize un script para subir fotos a una web el problema es ke cuando son varios megas el script falla... funciona asi... subo un zip ...
  #1 (permalink)  
Antiguo 27/11/2011, 12:33
 
Fecha de Ingreso: mayo-2011
Mensajes: 167
Antigüedad: 12 años, 11 meses
Puntos: 1
subir archivos por partes

hize un script para subir fotos a una web el problema es ke cuando son varios megas el script falla...

funciona asi... subo un zip con todas las fotos que necesito...
luego el script descomprime, elimina el zip
y pasa todas las fotos a una carpeta las redimensiona, por ultimo les agrega un logotipo en marca de agua...

al principio me funcionaba bien.. pero de repente empezo a marcar un error algo asi...
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 11264 bytes) in /home2/chi1708/public_html/admin/fotos.php on line 170

y lo que pienso es ke hace todo el proceso de una sola vez... talvez si pudiera procesar foto por foto.. y entre cada una hacer una breve pausa en el script omitiria este error...

que me sugieren?

les paso el codigo..
Código PHP:
Ver original
  1. <?php
  2. if (!function_exists("GetSQLValueString")) {
  3. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  4. {
  5.   if (PHP_VERSION < 6) {
  6.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  7.   }
  8.  
  9.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  10.  
  11.   switch ($theType) {
  12.     case "text":
  13.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  14.       break;    
  15.     case "long":
  16.     case "int":
  17.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  18.       break;
  19.     case "double":
  20.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  21.       break;
  22.     case "date":
  23.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  24.       break;
  25.     case "defined":
  26.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  27.       break;
  28.   }
  29.   return $theValue;
  30. }
  31. }
  32.  
  33. mysql_select_db($database_conectar, $conectar);
  34. $query_Recordset1 = "SELECT * FROM fotos ORDER BY id DESC";
  35. $Recordset1 = mysql_query($query_Recordset1, $conectar) or die(mysql_error());
  36. $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  37. $totalRows_Recordset1 = mysql_num_rows($Recordset1);
  38.  
  39. ini_set("memory_limit","30M");
  40.  
  41. //Incluimos la libreria
  42.   include('pclzip/pclzip.lib.php');
  43.  
  44.  
  45.  
  46. $editFormAction = $_SERVER['PHP_SELF'];
  47. if (isset($_SERVER['QUERY_STRING'])) {
  48.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  49. }
  50.  
  51. $names = "GALERY_".date('Ymdhis').".zip";
  52. if(is_uploaded_file($_FILES['archivo']['tmp_name'])) {
  53.         $ruta_destino = "../fotos/";
  54.         move_uploaded_file($_FILES['archivo']['tmp_name'], $ruta_destino . $names);
  55.     }  
  56.    
  57. $nombre=date('Ymdhis');
  58. $archivor=explode("\\", $_POST['portada']);
  59. $nombre_archivor=array_pop($archivor);
  60. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  61.   $insertSQL = sprintf("INSERT INTO fotos (archivo, fecha, titulo, portada, lugar, subcate) VALUES (%s, %s, %s, %s, %s, %s)",
  62.                        GetSQLValueString($nombre, "text"),
  63.                        GetSQLValueString($_POST['fec_ano'].$_POST['fec_mes'].$_POST['fec_dia'], "text"),
  64.                        GetSQLValueString($_POST['titulo'], "text"),
  65.                        GetSQLValueString($_FILES['portada']['name'], "text"),
  66.                        GetSQLValueString($_POST['lugar'], "text"),
  67.                        GetSQLValueString($_POST['subcate'], "text"));
  68.  
  69.   mysql_select_db($database_conectar, $conectar);
  70.   $Result1 = mysql_query($insertSQL, $conectar) or die(mysql_error());
  71.  
  72.    
  73. $archive = new PclZip($ruta_destino . $names);
  74. mkdir("../fotos/".$nombre, 0777);
  75. $ruta="../fotos/".$nombre;
  76.  
  77.   if ($archive->extract(PCLZIP_OPT_PATH, $ruta,
  78.                         PCLZIP_OPT_REMOVE_PATH, 'temp_install') == 0) {
  79.     die("Error : ".$archive->errorInfo(true));
  80.   }
  81. unlink($ruta_destino . $names);
  82.  
  83.  
  84. $directorio = "../fotos/".$nombre."/";
  85. $gestor = opendir($directorio);  
  86. $entradas = array();  
  87. while (false !== ($archivo = readdir($gestor))) {  
  88. $ext = strtolower(end(explode('.',$archivo)));  
  89. // Aqui haces la comparación  
  90. if (is_file($directorio.$archivo) && ($ext=='jpg' || $ext=='JPG' || $ext=='gif')) {
  91. $entradas[$archivo] = $directorio."/".$archivo;}}  
  92. asort($entradas);  
  93. closedir($gestor);  
  94. // Recorres cada uno de los archivos.  
  95. foreach($entradas as $file => $tiempo){  
  96. $image = imagecreatefromjpeg($directorio.$file);
  97. imagecopy($image, imagecreatefrompng("../images/logo2.png"), 0, 0, 0, 0, 280, 90);
  98. imagepng($image, $directorio.$file);
  99. }
  100.  
  101.            
  102.  
  103.   $insertGoTo = "fotos.php";
  104.   if (isset($_SERVER['QUERY_STRING'])) {
  105.     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  106.     $insertGoTo .= $_SERVER['QUERY_STRING'];
  107.   }
  108.   header(sprintf("Location: %s", $insertGoTo));
  109. }
  110.  
  111. function rrmdir($dir) {
  112.    if (is_dir($dir)) {
  113.      $objects = scandir($dir);
  114.      foreach ($objects as $object) {
  115.        if ($object != "." && $object != "..") {
  116.          if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
  117.        }
  118.      }
  119.      reset($objects);
  120.      rmdir($dir);
  121.    }
  122.  }
  123.  
  124. if ((isset($_GET['delete'])) && ($_GET['delete'] != "")) {
  125.   $deleteSQL = sprintf("DELETE FROM fotos WHERE id=%s",
  126.                        GetSQLValueString($_GET['delete'], "int"));
  127.  
  128.   mysql_select_db($database_conectar, $conectar);
  129.   $Result1 = mysql_query($deleteSQL, $conectar) or die(mysql_error());
  130.  
  131. rrmdir('../fotos/'.$_GET['carpeta']);
  132.  
  133. }
  134. ?>
  #2 (permalink)  
Antiguo 27/11/2011, 18:15
 
Fecha de Ingreso: enero-2010
Mensajes: 127
Antigüedad: 14 años, 3 meses
Puntos: 2
Respuesta: subir archivos por partes

Ese codigo es de dreamweaver por lo que veo, te recomendaria aumentar esto

ini_set("memory_limit","30M"); esta en la linea 40, colocale ini_set("memory_limit","50M"); y guarda. Prueba asi a ver si funciona.

Etiquetas: html, mysql, partes, sql
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 20:10.