Boa tarde amigos, meu codigo de upload de imagem faz o redimensionamento, tanto de width como tambem manipula o tamanho do arquivo final, bom vou mostrar o codigo e dizer o problema:
<?php
if (!empty($_FILES)) {
$idPai = $_POST['Session'];
$postId = $_POST['postId'];
$img = $_FILES['Filedata']['name'];
$img_nome = $_FILES['Filedata']['name'];
$ext = substr($img, -4);
$img = $postId.'-'.md5(uniqid(time())).$ext;
$targetPath = $_SERVER['DOCUMENT_ROOT'].$_REQUEST['folder'].'/';
$m = date('m');
$y = date('Y');
if(!file_exists($targetPath.$y)){ mkdir($targetPath.$y,0755);}
if(!file_exists($targetPath.$y.'/'.$m)){ mkdir($targetPath.$y.'/'.$m,0755);}
$targetPath = $_SERVER['DOCUMENT_ROOT'].$_REQUEST['folder'].'/'.$y.'/'.$m.'/';
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetFile = str_replace('//','/',$targetPath).$img;
$imgCad = $y.'/'.$m.'/'.$img;
$timestamp = date('Y-m-d H:i:s');
$cadastra = mysql_query("INSERT INTO up_posts_gb(post_id, id_pai, img_nome, img, data) VALUES('$postId', '$idPai', '$img_nome', '$imgCad', '$timestamp')");
print( mysql_error() );
$cadastra1 = mysql_query("INSERT INTO up_vendas(post_id, id_pai, img_nome, img, data) VALUES('$postId', '$idPai', '$img_nome', '$imgCad', '$timestamp')");
print( mysql_error() );
}
move_uploaded_file($tempFile,$targetFile);
str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile);
$imgsize = getimagesize($targetFile);
switch(strtolower(substr($targetFile, -3))){
case "jpg":
$image = imagecreatefromjpeg($targetFile);
break;
case "png":
$image = imagecreatefrompng($targetFile);
break;
case "gif":
$image = imagecreatefromgif($targetFile);
break;
default:
exit;
break;
}
$width = 800;
$height = $imgsize[1]/$imgsize[0]*$width;
$src_w = $imgsize[0];
$src_h = $imgsize[1];
$picture = imagecreatetruecolor($width, $height);
imagealphablending($picture, false);
imagesavealpha($picture, true);
$bool = imagecopyresampled($picture, $image, 0, 0, 0, 0, $width, $height, $src_w, $src_h);
if($bool){
switch(strtolower(substr($targetFile, -3))){
case "jpg":
header("Content-Type: image/jpeg");
$bool2 = imagejpeg($picture,$targetPath.$img,80);
break;
case "png":
header("Content-Type: image/png");
imagepng($picture,$targetPath.$img);
break;
case "gif":
header("Content-Type: image/gif");
imagegif($picture,$targetPath.$img);
break;
}
}
imagedestroy($picture);
imagedestroy($image);
echo '1';
?>
ok, linha abaixo limita em 800 o width da imagem:
$width = 800;
já a linha:
$bool2 = imagejpeg($picture,$targetPath.$img,80);
cria a imagem com 80% de qualidade, essa linha pega uma imagem de por exemplo 5MB e cria outra reduzindo a qualidade e setando as novos atributos da imagem com um resultado final de aproximadamente 300KB, é uma redução crucial e muito significativa para meu sistema.
o problema então é o seguinte, localhost isso funciona que é uma beleza, hospedado funciona em partes, se eu pego uma foto de uns 400KB e faço o upload e o tratamento por este codigo, funciona, se eu pego uma foto grande, de uns 5MB, com width de uns 1500 por exemplo, ele não trata, faz o upload e manda do jeito que ele pega, chega la na hospedagem a foto original sem resize nenhum.
já comparei o phpinfo meu local com o da hospedagem pra ver se tem algo errado e não acho o erro, alguém consegue me da uma luz