Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
então, eu to com um pequeno probleminha...
Eu peguei uma classe, em um site onde faz o resize quando faz o upload da imagen, mas tem 1
problema... O multiupload é em jquery, assim eu posso selecionar varios arquivos ao mesmo tempo
e fazer o up, so que dae ele da esse erro
Fatal error: Cannot redeclare class SimpleImage in D:\xampp\htdocs\euroclass\roteirospremium\viagens\admin\funcao_upload.php on line 22
Como que eu faco pra ele dar o resize em todas, pq ele so da o resize em 1, as outraso imagens dae nao vao....
Segue o codigo..
Cadastra_imagem.php
<?php
// Conexão....
include("../../conexao/conexao.php");
?>
<?php if(isset($_POST['upload'])){
$pasta = 'upload/';
foreach($_FILES["img"]["error"] as $key => $error){
if($error == UPLOAD_ERR_OK){
$tmp_name = $_FILES["img"]["tmp_name"][$key];
$cod = date('dmy') . '-' . $_FILES["img"]["name"][$key];
$nome = $_FILES["img"]["name"][$key];
$uploadfile = $pasta . basename($cod);
// Move Imagem
if(move_uploaded_file($tmp_name, $uploadfile)){
$id_imagem = ($_POST['id_imagem']);
// Inclui a Classe
include('funcao_upload.php');
$image = new SimpleImage();
$image->load($uploadfile);
$image->resizeToWidth(680);
$image->save($uploadfile);
// Retora se tudo ocorreu bem!
echo "O Arquivo " . $nome . " foi enviado com sucesso!<br />";
// Inseri no Banco de Dados
$inserir = mysql_query("INSERT INTO galeria (img, idimagem) VALUES ('$cod', '$id_imagem')");
}else{
echo "Erro ao enviar o arquivo " . $nome . "! Por favor tente outra vez!";
} } } }
$id_imagem = $_GET['id'];?>
<!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=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="script/jquery.js" /></script>
<script type="text/javascript" src="script/jquery.MultiFile.js" /></script>
</head>
<body>
<form name="upload_files" action="" enctype="multipart/form-data" method="post">
<input type="file" name="img[]" class="multi" maxlength="100" accept="jpeg|jpg|png|gif" />
<input type="hidden" name="id_imagem" value="<?php print($id_imagem); ?>">
<input type="submit" name="upload" value="Upload" />
</form>
</body>
</html>
Classe
<?php
/*
* File: SimpleImage.php
* Author: Simon Jarvis
* Copyright: 2006 Simon Jarvis
* Date: 08/11/06
* Link: http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details:
* http://www.gnu.org/licenses/gpl.html
*
*/
class SimpleImage {
var $image;
var $image_type;
function load($filename) {
$image_info = getimagesize($filename);
$this->image_type = $image_info[2];
if( $this->image_type == IMAGETYPE_JPEG ) {
$this->image = imagecreatefromjpeg($filename);
} elseif( $this->image_type == IMAGETYPE_GIF ) {
$this->image = imagecreatefromgif($filename);
} elseif( $this->image_type == IMAGETYPE_PNG ) {
$this->image = imagecreatefrompng($filename);
}
}
function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image,$filename,$compression);
} elseif( $image_type == IMAGETYPE_GIF ) {
imagegif($this->image,$filename);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng($this->image,$filename);
}
if( $permissions != null) {
chmod($filename,$permissions);
}
}
function output($image_type=IMAGETYPE_JPEG) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image);
} elseif( $image_type == IMAGETYPE_GIF ) {
imagegif($this->image);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng($this->image);
}
}
function getWidth() {
return imagesx($this->image);
}
function getHeight() {
return imagesy($this->image);
}
function resizeToHeight($height) {
$ratio = $height / $this->getHeight();
$width = $this->getWidth() * $ratio;
$this->resize($width,$height);
}
function resizeToWidth($width) {
$ratio = $width / $this->getWidth();
$height = $this->getheight() * $ratio;
$this->resize($width,$height);
}
function scale($scale) {
$width = $this->getWidth() * $scale/100;
$height = $this->getheight() * $scale/100;
$this->resize($width,$height);
}
function resize($width,$height) {
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
$this->image = $new_image;
}
}
?>
Vlws, aguardo retorno, só falta isso pra eu termina esse sistema... e se alguemm puder me indicar uma apostila, livro ficaria grato..
Att. Luis Felipe R. Agottani
Carregando comentários...