Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php header("Content-Type: text/html; charset=ISO-8859-1",true);
- /**
- * Conexão Mysql
- */
- $conn = mysql_connect('localhost', 'root', '');
- $db = mysql_select_db('db');
- $file = $_FILES['Filedata'];
- $album = (int) $_POST['id'];
- $filename = $file['name'];
- $filetmp = $file['tmp_name'];
- $filetype = $file['type'];
- $file_info = pathinfo($filename);
- $md5_name = substr(md5(microtime()),0,10) .'.'. $file_info['extension'];
- $query = mysql_query ("INSERT INTO albums_photos (album, file) VALUES ('$album', '$md5_name')");
- $path = $file['tmp_name'];
- $new_path = "uploads/".$md5_name;
- move_uploaded_file($path, $new_path);
- // Vamos usar a biblioteca WideImage para o redimensionamento das imagens
- require("lib/WideImage/WideImage.php");
- // Carrega a imagem enviada
- $original = WideImage::load($new_path);
- // Redimensiona a imagem original para 1024x768 caso ela seja maior que isto e salva
- $original->resize(640, 480, 'inside', 'down')->saveToFile($new_path, null, 90);
- // Cria a miniatura
- $ext = end(explode(".", $new_path)); // Pega a extensão do arquivo
- $thumb = str_replace(".$ext", "_thumb.$ext", $new_path); // Substitui a extensão
- $original->resize(210, 158, 'inside', 'down')->saveToFile($thumb, null, 90); // Redimensiona e salva
- echo mysql_insert_id(); // Retorna o id da foto
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement