Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2014
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.36 KB | None | 0 0
  1. <HTML>
  2.     <HEAD>
  3.         <title>Subir im&aacute;genes - Galileo</title>
  4.         <LINK rel=stylesheet href=css/main.css />
  5.         <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
  6.     </HEAD>
  7.     <BODY>
  8.         <form action='subidas-script.php' method='post' enctype='multipart/form-data'>
  9.  
  10. <?php
  11.  
  12. error_reporting(E_ALL);
  13.  
  14. /* Files: */
  15.  
  16. require_once 'session.php';
  17. require_once 'class.image.php';
  18. require_once '../include/connect.php';
  19.  
  20. /* Variables: */
  21.  
  22. $direccion = "http://localhost/proyect/";
  23. //The following variable will be used in file details.php in the for function:
  24. $_SESSION['file'] = count($_FILES['file']['name']);
  25.  
  26.  
  27. for ($i = 0; $i < count($_FILES['file']['name']); $i++)
  28. {
  29.     // Check if there are no errors
  30.     if ($_FILES['file']['error'][$i])
  31.     {
  32.         echo "<br />Se ha producido un error al subir al archivo: ". $_FILES['file']['error'][$i];
  33.     }
  34.     else
  35.     {
  36.         // Check that it's a jpeg
  37.         if ($_FILES['file']['type'][$i] !== 'image/jpeg')
  38.         {
  39.             echo "<br />Se ha producido un error, el archivo debe ser una im&aacute;gen .jpg, el archivo subido es del tipo: " . $_FILES['file']['type'][$i];
  40.         }
  41.         else
  42.         {
  43.             // Check that the file is of valid size
  44.             if ($_FILES['file']['size'][$i] < 1)
  45.             {
  46.                 echo "<br />Se ha producido un error, el archivo tiene un peso inv&aacute;lido. Por favor intente nuevamente. Si el problema persiste, intente con otro archivo.";
  47.             }
  48.             else
  49.             {
  50.                 $new_file_name = uniqid(false, true);
  51.                 // Resizing the image if it's too large
  52.                 list($width, $height) = getimagesize($_FILES['file']['tmp_name'][$i]);
  53.                 if ($width || $height > 800)
  54.                 {
  55.                     if (!resize($_FILES['file']['tmp_name'][$i],$new_file_name))
  56.                     {
  57.                         echo "<br />Se ha producido un error al redimensionar el archivo.";
  58.                     }
  59.                     else
  60.                     {
  61.                         // Create a thumbnail
  62.                         resize_thumb ('../galeria/productos/'.$new_file_name.".jpg",$new_file_name);
  63.                         // Check that the query was successful
  64.                         if(!mysqli_query($db, "INSERT INTO `imagenes` (`tid`, `direccion`, `archivo`, `nombre`, `fecha`) VALUES (NULL, '".$direccion.(string)$new_file_name."', '".(string)$new_file_name.".jpg', '".$new_file_name."', '".time()."')"))
  65.                         {
  66.                             echo "Ha ocurrido un error: ".mysqli_error($db);
  67.                         }
  68.                        
  69.                         $_SESSION['lid'] .= ",".(int)mysqli_insert_id($db);
  70.                         while (mysqli_fetch_row(mysqli_query($db, "SELECT `tid` FROM `imagenes` WHERE `tid` = '".mysqli_insert_id($db)."'")))
  71.                         {
  72.                             @$tr1 .= "<td><img src='".$direccion."/thumbnails/".$new_file_name."_thumb.jpg' /></td>";
  73.                             @$tr2 .= "<td><textarea name='descripcion'></textarea></td>";
  74.                         }
  75.                     }
  76.                 }
  77.             }
  78.         }
  79.     }
  80. }
  81. //Comment for Stack Overflow: below are some functions I deleted because they weren't related to my problem
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement