upload multiplo com redimensionamento
Boa noite pessoal, estou tendo uma dor de cabeça, sou iniciante.
Tenho um arquivo que envia múltiplas imagens, só que não redimensiona.
Inclui uma classe para redimensionar que ja uso em outros arquivos porém não em múltiplos.
O problema é que sempre dá erro, como se o redirecionamento não estivesse recebendo as imagens. Segue o código e a classe.
Se poderem me ajudar, desde já muito obrigado!
<?php if(session_is_registered("$var_sessaor")) { ?>
<?php
include("FCKeditor/fckeditor.php");
include_once ('Redimensiona.php');
$id=$_GET['id'];
require('saidas.php');
if(isset($_POST['enviar']))
{
foreach($_FILES['foto']['name'] as $key => $arquivo)
{
if($arquivo!='')
{
//redimensiona
$foto = $_FILES['foto'][$key];
$redim = new Redimensiona();
$imagem = $redim->Redimensionar($foto, 800, '../imgs/projetos_fotos/');
//upload sem redimensionamento
/*$hash=md5(microtime()).'.jpg';
if(move_uploaded_file($_FILES['foto']['tmp_name'][$key],'../imgs/projetos_fotos/'.$hash))*/
{
$legenda=$_POST['legenda'][$key];
mysql_query("INSERT INTO projetos_fotos (projetos,foto,legenda) VALUES ('$id','$imagem','$legenda')");
}
}
}
throw_alert('Fotos enviadas com sucesso!','?p=projetos_fotos2&id='.$id);
}
elseif(isset($_GET['foto']))
{
$fotoid=$_GET['foto'];
$select=mysql_query("SELECT * FROM projetos_fotos WHERE id='$fotoid'");
$vessel=mysql_fetch_array($select);
@unlink('../imgs/projetos_fotos/'.$vessel['foto']);
$del=mysql_query("DELETE FROM projetos_fotos WHERE id='$fotoid'");
if($del)
throw_alert('Foto removida com sucesso.','?p=books_fotos&id='.$vessel['books']);
}
?>
<!--GERAL-->
<div class="panel panel-default">
<div style="margin-top:10px; padding:5px;" class="borda">
<h1>Fotos para o Book</h1>
<p><a href="?p=projetos" class="btn btn-default" style="width: 115px;">Voltar</a></p>
</div>
<div class="panel-heading no-collapse">
<span >Cadastrar fotos para: </span>
<span style="font-weight:bold;">
<?php
$id=$_GET['id'];
$select=mysql_query("SELECT * FROM projetos WHERE id='$id'");
$display=mysql_fetch_array($select);
print ''.$display['titulo'].'';
?>
</span>
</div>
<!--form-->
<div style="margin-top:30px; padding:10px; overflow:hidden; max-width:800px;" >
<form name="dados" method="post" action="?p=projetos_fotos2&id=<?php print $id; ?>" enctype="multipart/form-data">
<?php
for($i=0;$i<6;$i+=2)
{
?>
<div style="col-lg-4">
<div class="form-group">
<label style="font-size:11px;">Foto</label>
<input type="file" <?php print 'name="foto['.$i.']"'; ?> />
</div>
</div>
<div style="col-lg-4">
<div class="form-group">
<label style="font-size:11px;">Foto</label>
<input type="file" <?php print 'name="foto['.($i+1).']"'; ?> />
</div>
</div>
<?php } ?>
<div style="clear:both"></div>
<input type="submit" name="enviar" value="Adicionar" class="btn btn-primary" />
</form>
</div>
<!-- form-->
<div class="panel-heading no-collapse" style="margin-top:40px;">
<span >Fotos Cadastradas</span>
</div>
<!--fotos-->
<div style="margin-top:30px; overflow:hidden;">
<?php
$sql = mysql_query("SELECT * FROM projetos_fotos WHERE projetos='$id' ORDER BY id DESC LIMIT 100");
while($x = mysql_fetch_array($sql))
{
?>
<div align="center" style="width:200px; height:200px; float:left; background-color:#F4F4F4; padding:7px; margin:10px;">
<img src="../imgs/projetos_fotos/<?=$x['foto'];?>" width="185" height="139" border="0" /><br>
<!--<div style="font-size:11px; margin-top:10px;">'.$display['legenda'].'</div><br />-->
<div align="center" style="margin-top:10px;">
<a href="?p=projetos_fotos&foto=<?=$x['id'];?>" class="btn btn-default" onclick="return confirm('Deseja mesmo remover?')" >
Excluir Foto</a>
</div>
</div>
<?php } ?>
</div>
<!--fotos-->
</div>
<!--GERAL-->
<?php } ?>
------------------------------------------------------------------------------------------------
//CLASSE DE REDIMENDIONAR
<?php
class Redimensiona{
public function Redimensionar($imagem, $largura, $pasta){
$name = md5(uniqid(rand(),true));
if ($imagem['type']=="image/jpeg"){
$img = imagecreatefromjpeg($imagem['tmp_name']);
}else if ($imagem['type']=="image/gif"){
$img = imagecreatefromgif($imagem['tmp_name']);
}else if ($imagem['type']=="image/png"){
$img = imagecreatefrompng($imagem['tmp_name']);
}
$x = imagesx($img);
$y = imagesy($img);
$autura = ($largura * $y)/$x;
$nova = imagecreatetruecolor($largura, $autura);
imagecopyresampled($nova, $img, 0, 0, 0, 0, $largura, $autura, $x, $y);
if ($imagem['type']=="image/jpeg"){
$local="$pasta/$name".".jpg";
$imagemName = $name.".jpg";
imagejpeg($nova, $local);
}else if ($imagem['type']=="image/gif"){
$local="$pasta/$name".".gif";
$imagemName = $name.".gif";
imagegif($nova, $local);
}else if ($imagem['type']=="image/png"){
$local="$pasta/$name".".png";
$imagemName = $name.".png";
imagepng($nova, $local);
}
imagedestroy($img);
imagedestroy($nova);
return $imagemName;
}
}
?>Discussão (4)
Carregando comentários...