como renomear o arquivo??
olá, gostaria de saber como posso renomer o arquivo quando enviar ele.
tipo, eu envio um imagem e ela se chama: imasters.jpg e tem que renomear para imasters.thumb.jpg, olha o script que fiz só que não renome, olha pra ver:
index.php
<?phpinclude "class.pizza.php";$pizza = new pizza();if(isset($_POST["submit"])){ $image = isset($_FILES["image"]) ? $_FILES["image"] : false; $dir = "images/".$image["name"]; if(!file_exists($dir)){ if(!eregi("^image\/(gif|bmp|png|jpg|jpeg)$", $image["type"])){ $error[] = "Arquivo com extensão inválido!"; } else{ $nome = explode(".", $image["name"]); $thumb = $nome[0].".thumb.".$nome[1]; //se usar echo $thumb; ele imprime o nome certo $pizza->thumb($image["tmp_name"], $dir, 80); $error[] = "Imagem enviada com sucesso!"; } } else{ $error[] = "Essa imagem já existe!"; }}?>
class.pizza.php
<?phpclass pizza { 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); } }}?>se algum poder ajudar, fico gratro :)Discussão (3)
Carregando comentários...