Advertisement
gersonab

upload.php

May 22nd, 2012
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.31 KB | None | 0 0
  1. <?php header("Content-Type: text/html;  charset=ISO-8859-1",true);
  2. /**
  3.  * Conexão Mysql
  4.  */
  5. $conn = mysql_connect('localhost', 'root', '');
  6. $db   = mysql_select_db('db');
  7.  
  8. $file = $_FILES['Filedata'];
  9.  
  10. $album = (int) $_POST['id'];
  11. $filename = $file['name'];
  12. $filetmp = $file['tmp_name'];
  13. $filetype = $file['type'];
  14.  
  15. $file_info = pathinfo($filename);
  16. $md5_name = substr(md5(microtime()),0,10) .'.'. $file_info['extension'];
  17.  
  18.  
  19. $query = mysql_query ("INSERT INTO albums_photos (album, file) VALUES ('$album', '$md5_name')");
  20.  
  21. $path     = $file['tmp_name'];
  22. $new_path = "uploads/".$md5_name;
  23.  
  24. move_uploaded_file($path, $new_path);
  25.  
  26. // Vamos usar a biblioteca WideImage para o redimensionamento das imagens
  27. require("lib/WideImage/WideImage.php");
  28.  
  29. // Carrega a imagem enviada
  30. $original = WideImage::load($new_path);
  31.  
  32. // Redimensiona a imagem original para 1024x768 caso ela seja maior que isto e salva
  33. $original->resize(640, 480, 'inside', 'down')->saveToFile($new_path, null, 90);
  34.  
  35. // Cria a miniatura
  36. $ext = end(explode(".", $new_path)); // Pega a extensão do arquivo
  37. $thumb = str_replace(".$ext", "_thumb.$ext", $new_path); // Substitui a extensão
  38.  
  39. $original->resize(210, 158, 'inside', 'down')->saveToFile($thumb, null, 90); // Redimensiona e salva
  40.  
  41. echo mysql_insert_id(); // Retorna o id da foto
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement