Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

serginho_the_best

enviar thumb e imagem original

Recommended Posts

esse script envia uma thumb e a imagem original, a thumb é renomeada para a imagem original ficar na mesma página, aah e também todos os espaço é substituto por underline e as letra maiuscula passa a ser minisculas, brom vamos lá :)

 

index.php

<?phpinclude "class.upload.php";$upload = new upload();if(isset($_POST["submit"])){	$image = isset($_FILES["image"]) ? $_FILES["image"] : false;	$dir = "images/";	$img = strtolower(str_replace(" ", "_", $image["name"]));	if(!file_exists($dir.$img)){		if(!eregi("^image\/(pjpeg|jpeg|png|gif|bmp)$", $image["type"])){			$error[] = "Arquivo com extensão inválido!";		}		else{			$upload->thumb($image["tmp_name"], $dir."thumb_".$img, 80);			move_uploaded_file($image["tmp_name"], $dir.$img);			$error[] = "Imagem enviada com sucesso!";		}	}	else{		$error[] = "Essa imagem já existe!";	}}?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Upload de Imagem</title></head><body><?phpif(isset($error)){	for($i=0;$i<count($error);$i++){		echo "<script>alert('".$error[$i]."');</script>";	}}?><form action="index.php" method="post" enctype="multipart/form-data"><input type="file" name="image" /><br /><input type="submit" name="submit" value="Enviar" /></form></body></html>

class.upload.php

<?phpclass upload{	function thumb($image, $dir, $new_width){		$source = imagecreatefromstring(file_get_contents($image));		list($width, $height) = getimagesize($image);		if ($width>$new_width){			$new_height = ($new_width/$width) * $height;			$thumb = imagecreatetruecolor($new_width, $new_height);			imagecopyresampled($thumb, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height);			imagejpeg($thumb, $dir, 100);		}		else{			move_uploaded_file($image, $dir);		}	}}?>

é só isso, simples e eficaz :)

mais em http://www.serginhothebest.cjb.net/

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.