Ver Mensaje Individual
  #1 (permalink)  
Antiguo 11/05/2014, 13:29
nakoart
 
Fecha de Ingreso: junio-2010
Mensajes: 10
Antigüedad: 13 años, 10 meses
Puntos: 0
Una mano resumir PHP que no se aun

Alguien me puede echar una mano a resumir este código, soy algo novato y nuevo, por no decir mucho, y es todo corta y pega, para poder subir 4 imágenes, donde la imagen se renombrar a la id del cliente y la se crea una carpeta con el mismo nombre que la id alojando dentro las 4 imágenes.

Muchas gracias.

Código PHP:
<?php require_once('Connections/conexion_tareas.php'); ?>
<?php
$currentPage 
$_SERVER["PHP_SELF"];

function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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")) {
  
$archivos_disp_ar = array('jpg''jpeg''gif''png');
  
$carpeta 'Upload';
  
$imagen $_FILES['imagen1']['tmp_name'];
  
$imagen2 $_FILES['imagen2']['tmp_name'];
  
$imagen3 $_FILES['imagen3']['tmp_name'];
  
$imagen4 $_FILES['imagen4']['tmp_name'];
  
$nombrebre_orig $_FILES['imagen1']['name'];
  
$nombrebre_orig2 $_FILES['imagen2']['name'];
  
$nombrebre_orig3 $_FILES['imagen3']['name'];
  
$nombrebre_orig4 $_FILES['imagen4']['name'];
  
$array_nombre explode('.',$nombrebre_orig);
  
$array_nombre2 explode('.',$nombrebre_orig2);
  
$array_nombre3 explode('.',$nombrebre_orig3);
  
$array_nombre4 explode('.',$nombrebre_orig4);
  
$cuenta_arr_nombre count($array_nombre);
  
$cuenta_arr_nombre2 count($array_nombre2);
  
$cuenta_arr_nombre3 count($array_nombre3);
  
$cuenta_arr_nombre4 count($array_nombre4);
  
$extension strtolower($array_nombre[--$cuenta_arr_nombre]);
  
$extension strtolower($array_nombre2[--$cuenta_arr_nombre2]);
  
$extension strtolower($array_nombre3[--$cuenta_arr_nombre3]);
  
$extension strtolower($array_nombre4[--$cuenta_arr_nombre4]);
  
  
  
if(!
in_array($extension$archivos_disp_ar)) $error "La cagaste 1 archivo error bien cagada";

if(empty(
$error)){
        
$query "SELECT LAST_INSERT_ID()+1 FROM archivos";
        
$last_id mysql_resultmysql_query$query ), 0);
        
mkdir("Upload/".$last_id,0777);
        
$nombre_nuevo $last_id.'-1.'.$extension;
        
$nombre_nuevo2 $last_id.'-2.'.$extension;
        
$nombre_nuevo3 $last_id.'-3.'.$extension;
        
$nombre_nuevo4 $last_id.'-4.'.$extension;
        
$carpeta_mas_nombre "$carpeta/$last_id/";
        
$nombre_nuevo_con_carpeta $carpeta_mas_nombre.$nombre_nuevo;
        
$nombre_nuevo_con_carpeta2 $carpeta_mas_nombre.$nombre_nuevo2;
        
$nombre_nuevo_con_carpeta3 $carpeta_mas_nombre.$nombre_nuevo3;
        
$nombre_nuevo_con_carpeta4 $carpeta_mas_nombre.$nombre_nuevo4;
        
$mover_archivos move_uploaded_file($imagen $nombre_nuevo_con_carpeta);
        
$mover_archivos2 move_uploaded_file($imagen2 $nombre_nuevo_con_carpeta2);
        
$mover_archivos3 move_uploaded_file($imagen3 $nombre_nuevo_con_carpeta3);
        
$mover_archivos4 move_uploaded_file($imagen4 $nombre_nuevo_con_carpeta4);
        
chmod($nombre_nuevo_con_carpeta,0777);
        
chmod($nombre_nuevo_con_carpeta2,0777);
        
chmod($nombre_nuevo_con_carpeta3,0777);
        
chmod($nombre_nuevo_con_carpeta4,0777);
      
      
    
$insertSQL sprintf("INSERT INTO archivos (Imagen1, Imagen2, Imagen3, Imagen4) VALUES (%s,%s,%s,%s)",
                            
GetSQLValueString($nombre_nuevo"text"),
                            
GetSQLValueString($nombre_nuevo2"text"),
                            
GetSQLValueString($nombre_nuevo3"text"),
                               
GetSQLValueString($nombre_nuevo4"text"));
    
      
mysql_select_db($database_conexion_archivos$conexion_archivos);
      
$Result1 mysql_query($insertSQL$conexion_archivos) or die(mysql_error());
    }
}


mysql_select_db($database_conexion_archivos$conexion_archivos);
$query_Recordset1 "SELECT * FROM archivos";
$Recordset1 mysql_query($query_Recordset1$conexion_archivos) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);


y si lo quisiera unir a este otro y que funcionase? es que quiero unirlo a un formulario y que a la vez que se registra al cliente se suban sus fotos, y por separa funciona pero juntos... nada y no se donde falla.

Código PHP:
 <?php require_once('Connections/conexion_tareas.php'); ?>
<?php
$currentPage 
$_SERVER["PHP_SELF"];

function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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 tareas (Nombre, Telefono, Fecha, Observaciones, Tipo) VALUES (%s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['Nombre'], "text"),
                       
GetSQLValueString($_POST['Telefono'], "int"),
                       
GetSQLValueString($_POST['Fecha'], "text"),
                       
GetSQLValueString($_POST['Observaciones'], "text"),
                       
GetSQLValueString($_POST['Tipo'], "text"));
                   

  
mysql_select_db($database_conexion_tareas$conexion_tareas);
  
$Result1 mysql_query($insertSQL$conexion_tareas) or die(mysql_error());

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


$startRow_consulta_tareas $pageNum_consulta_tareas $maxRows_consulta_tareas;

mysql_select_db($database_conexion_tareas$conexion_tareas);
$query_consulta_tareas "SELECT * FROM tareas";
$query_limit_consulta_tareas sprintf("%s LIMIT %d, %d"$query_consulta_tareas$startRow_consulta_tareas$maxRows_consulta_tareas);
$consulta_tareas mysql_query($query_limit_consulta_tareas$conexion_tareas) or die(mysql_error());
$row_consulta_tareas mysql_fetch_assoc($consulta_tareas);
?>

Última edición por Triby; 11/05/2014 a las 14:55 Razón: Bajarle volúmen al texto! xD