Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <HTML>
- <HEAD>
- <title>Subir imágenes - Galileo</title>
- <LINK rel=stylesheet href=css/main.css />
- <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
- </HEAD>
- <BODY>
- <form action='subidas-script.php' method='post' enctype='multipart/form-data'>
- <?php
- error_reporting(E_ALL);
- /* Files: */
- require_once 'session.php';
- require_once 'class.image.php';
- require_once '../include/connect.php';
- /* Variables: */
- $direccion = "http://localhost/proyect/";
- //The following variable will be used in file details.php in the for function:
- $_SESSION['file'] = count($_FILES['file']['name']);
- for ($i = 0; $i < count($_FILES['file']['name']); $i++)
- {
- // Check if there are no errors
- if ($_FILES['file']['error'][$i])
- {
- echo "<br />Se ha producido un error al subir al archivo: ". $_FILES['file']['error'][$i];
- }
- else
- {
- // Check that it's a jpeg
- if ($_FILES['file']['type'][$i] !== 'image/jpeg')
- {
- echo "<br />Se ha producido un error, el archivo debe ser una imágen .jpg, el archivo subido es del tipo: " . $_FILES['file']['type'][$i];
- }
- else
- {
- // Check that the file is of valid size
- if ($_FILES['file']['size'][$i] < 1)
- {
- echo "<br />Se ha producido un error, el archivo tiene un peso inválido. Por favor intente nuevamente. Si el problema persiste, intente con otro archivo.";
- }
- else
- {
- $new_file_name = uniqid(false, true);
- // Resizing the image if it's too large
- list($width, $height) = getimagesize($_FILES['file']['tmp_name'][$i]);
- if ($width || $height > 800)
- {
- if (!resize($_FILES['file']['tmp_name'][$i],$new_file_name))
- {
- echo "<br />Se ha producido un error al redimensionar el archivo.";
- }
- else
- {
- // Create a thumbnail
- resize_thumb ('../galeria/productos/'.$new_file_name.".jpg",$new_file_name);
- // Check that the query was successful
- 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()."')"))
- {
- echo "Ha ocurrido un error: ".mysqli_error($db);
- }
- $_SESSION['lid'] .= ",".(int)mysqli_insert_id($db);
- while (mysqli_fetch_row(mysqli_query($db, "SELECT `tid` FROM `imagenes` WHERE `tid` = '".mysqli_insert_id($db)."'")))
- {
- @$tr1 .= "<td><img src='".$direccion."/thumbnails/".$new_file_name."_thumb.jpg' /></td>";
- @$tr2 .= "<td><textarea name='descripcion'></textarea></td>";
- }
- }
- }
- }
- }
- }
- }
- //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