austinnnnn Posted June 26, 2013 Share Posted June 26, 2013 So i have a website, here i have a backoffice. In the backoffice i can add new "places" and when i add a new place i want to be able to upload 1 picture of it. All good till now. So i have a from, and i want the image i upload do be resized to 800x600, and to create a thumbnail of 200px x 200px. So can someone help me? What is the best way to do this? Just store the path of the 800x600 image on the db and save the thumbnail with the same name of the 800x600 image but with thum in the front? Or save both paths in the db? Because the main goal is to show the place in the frontpage, like this: The thumb with the name of the place, and when i click on the thumb, i will get the 800x600 image with a lightbox. Can someone help me please? Quote Link to comment Share on other sites More sharing options...
litebearer Posted June 26, 2013 Share Posted June 26, 2013 (edited) this may help you get started http://www.nstoia.com/sat/resize/ also... http://www.nstoia.com/sat/crop/ Edited June 26, 2013 by litebearer Quote Link to comment Share on other sites More sharing options...
austinnnnn Posted June 26, 2013 Author Share Posted June 26, 2013 This is what i got: <?php include('dbconnect.php'); //ira verificar se clicou no botao enviar if(isset($_POST['enviar'])){ $nomesitio = $_POST['nome']; $horario = $_POST['horario']; $contato = $_POST['contato']; $morada = $_POST['morada']; $tipo = $_POST['tipo']; $freguesias = $_POST['freguesias']; //o nome original do arquivo no computador do utilizador $arqName = $_FILES['arquivo']['name']; //o tipo mime do arquivo $arqType = $_FILES['arquivo']['type']; //o tamanho do arquivo $arqSize = $_FILES['arquivo']['size']; //o nome temporario do arquivo com que foi guardado no servidor $arqTemp = $_FILES['arquivo']['tmp_name']; //o codigo de erro associado a este upload de arquivo $arqError = $_FILES['arquivo']['error']; //lista de tipos de arquivos permidos $tiposPermitidos = array('image/gif', 'image/jpeg', 'image/jpg', 'image/png'); //tamanho maximo $tamanhoPermitido = 6024 * 3000; if ($arqError == 0){ //verifica o tipo de arquivo enviado if(array_search($arqType, $tiposPermitidos) === false){ $retorno = '<span class="no">O tipo de arquivo enviado é invalido!</span>' ; //verifica o tamanho do arquivo enviado }elseif ($arqSize > $tamanhoPermitido){ $retorno = '<span class="no">O tamanho do arquivo enviado e maior que o limite!</span>'; }else{ $pasta = 'images_sitios/'; //pega a extensao do arquivo enviado $extensaoTemp = explode('.',$arqName); $extensao = strtolower(end($extensaoTemp)); //define o nome do arquivo usando um Unix TimesTamp $nome = time(). '.' . $extensao; $upload = move_uploaded_file($arqTemp, $pasta . $nome); if ($upload === true){ $ficheiro = $pasta.$nome; }else{ $retorno = '<span class="no">Nao foi possivel fazer o upload da imagem!</span>'; } } } if(empty($ficheiro)){ $retorno = '<span class="quase">Insira a imagem!</span>'; } //verifica se a variavel retorno estiver vazia (nao conter erro) if(empty($retorno)){ //cria uma query Mysql $query = mysql_query("INSERT INTO sitio (nome_sitio, horario, contato, morada, imagem, id_tipo, id_freguesia) VALUES ('$nomesitio','$horario','$contato','$morada','$ficheiro','$tipo','$freguesias')") or die (mysql_error()); //se a query existe entao a pagina é redireccionada if($query === true){ $sucesso = '<span class="yes">Sitio inserido com sucesso!</span>'; echo $sucesso; } }else{ echo $retorno; } } ?> The image is placed in the folder, and the path on db. I just want help on resizing the image to 800x600 or something, and to creathe the thumb for it. And also where to save the thumb path Quote Link to comment Share on other sites More sharing options...
happypete Posted June 29, 2013 Share Posted June 29, 2013 this post might help: http://forums.phpfreaks.com/topic/268852-image-upload-validation-not-working/page-2?do=findComment&comment=1381699 just resize the image twice (process.php): (this script below also creates a randon name, its just a copy and past from one of my projects) // *** Create 'random number' + 'random_name' for image name $imagename = time() . '_' . mt_rand(1000,9999) . '_' . 'randon_name' . '.jpg'; // What Directories to put the images $largelocation = '/home/public_html/images/'; $thumblocation = '/home/public_html/images/thumb/'; //thumbnail location $large = $largelocation . $imagename; $thumb = $thumblocation . $imagename; // *** 1) Initialise / load image $resizeObj = new resize($newPath); // *** 2) Resize LARGE image (options: exact, portrait, landscape, auto, crop) $resizeObj -> resizeImage(800, 600, 'auto'); //was 650, 487 wass 667, 500 // *** 3) Save image + define quality $resizeObj -> saveImage($large, 85); // *** 4) Initialise / load image for second resize $resizeObj = new resize($newPath); // *** 5) Resize THUMB (options: exact, portrait, landscape, auto, crop) $resizeObj -> resizeImage(150, 100, 'crop'); //was 220, 165 // *** 6) Save image + define quality $resizeObj -> saveImage($thumb, 85); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.