Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Amigos já rodei quase todo o forum atraz de resolver um problema na função que verifica o tamanho da imagem, veja o seguinte erro que acontece quando faço o upload da imagem para meu servidor:
Warning: getimagesize(/public_html/meusite/pasta/admin/upload_imagens/pdil194046.jpg)
[function.getimagesize]: failed to open stream: No such file or directory
in /home/empresa/public_html/meusite/pasta/admin/thumbnail.php on line 80
Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions
in /home/empresa/public_html/meusite/pasta/admin/thumbnail.php on line 100
I - Gostaria de saber se este erro é porque no php.ini não está habilitado no meu servidor que hospedo o site.
II - Gostaria de saber se isto pode ser um erro no código fonte da pagina, peguei este código na web para aprendizagem... veja o codigo do arquivo "thumbnail.php"
CODE
<?php
/*******************************************************************
Zenith Picture Gallery
Written by and copyright © Ali Almossawi
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.
*******************************************************************/
class ImageManipulator {
//----------------------
//constructor
//----------------------
function ImageManipulator() {}
//----------------------
//checkGD(): check for GD2 support
//----------------------
function checkGD() {
$msg = 1;
if (!function_exists("gd_info")) $msg = "Seu servidor nao suporta GD2.";
return $msg;
}
//----------------------
//decider(): Manage image depending on type
//----------------------
function decider($image_type, $filename, $width, $height, $quality, $path, $path_server, $suffix, $mode) {
$image_type = strtolower($image_type);
switch($image_type) {
case 'jpg':
$this -> doItJpeg($filename, $width, $height, $quality, $path, $path_server, $suffix, $mode);
break;
case 'jpeg':
$this -> doItJpeg($filename, $width, $height, $quality, $path, $path_server, $suffix, $mode);
break;
case 'png':
$this -> doItPng($filename, $width, $height, $path, $path_server, $suffix, $mode);
break;
default:
}
}
//----------------------
//doItJpeg(): resize the image
//----------------------
function doItJpeg($filename, $width, $height, $quality, $path, $path_server, $suffix, $mode) {
//$this -> checkGD()
$msg = "1"; //initially, assume all is well
//first, create a blank image
$bits = explode(".", $filename);
$thumb_filename = $bits[0] . $suffix . "." . $bits[1];
$path_thumb = $path_server . $thumb_filename;
$path_server .= $filename;
/*$im = @imagecreatefromjpeg($path); //attempt to open blank image
//courtesy (vic at zymsys dot com)
if (!$im) { //check if it failed
$im = imagecreate(150, 30); //create blank image
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
imagestring($im, 1, 5, 5, "Error loading $filename", $tc); //output error message
}*/
$size = GetImageSize($path_server); //get width/height (path support from PHP 4.05)
$image = @imagecreatefromjpeg($path_server); //attempt to open original image
//resize only if bigger than than the allowed thumbnail size
if($size[0]>$width || $size[1]>$height) {
//courtesy "User contributed notes" at php.net
if ($size[0]>=$size[1]) { //if width is greater than height or equal
$sizemin[0]=$width;
$sizemin[1]=$height;
}
if ($size[1]>$size[0]) { //if height is greater than width
$sizemin[0]=$height;
$sizemin[1]=$width;
}
}
else {
$sizemin[0]=$size[0];
$sizemin[1]=$size[1];
}
$thumbnail = imagecreatetruecolor($sizemin[0],$sizemin[1]);
@ImageCopyResampled($thumbnail, $image, 0, 0, 0, 0, $sizemin[0], $sizemin[1], $size[0], $size[1]); //resize and resample image
//chmod original file to 0777 temporarily, then return to 0644
if(!@chmod($path_server,0777))
if($config['debug_mode'] == 1) echo "Não foi possível alterar o chamod do diretório: ($path_server)";
@ImageDestroy($image); //free memory
if (!@ImageJPEG($thumbnail, $path_thumb, $quality)) { // try to save thumbnail image
$msg .= "Não foi possível criar o thumbnail";
}
if(!@chmod($path_server, 0644))
if($config['debug_mode'] == 1) echo "Não foi possível alterar o chamod do diretório: ($path_server)";
return $msg;
}
//----------------------
//doItPng(): resize the image
//----------------------
function doItPng($filename, $width, $height, $path, $path_server, $suffix, $mode) {
$msg = "1"; //initially, assume all is well
$bits = explode(".", $filename);
$thumb_filename = $bits[0] . $suffix . "." . $bits[1];
$path_thumb = $path_server . $thumb_filename;
$path_server .= $filename;
$size = GetImageSize($path_server); //get width/height (path support from PHP 4.05)
$image = @imagecreatefrompng($path_server); //attempt to open original image
//resize only if bigger than than the allowed thumbnail size
if($size[0]>$width || $size[1]>$height) {
//courtesy "User contributed notes" at php.net
if ($size[0]>=$size[1]) { //if width is greater than height or equal
$sizemin[0]=$width;
$sizemin[1]=$height;
}
if ($size[1]>$size[0]) { //if height is greater than width
$sizemin[0]=$height;
$sizemin[1]=$width;
}
}
else {
$sizemin[0]=$size[0];
$sizemin[1]=$size[1];
}
$thumbnail = imagecreatetruecolor($sizemin[0],$sizemin[1]);
@ImageCopyResampled($thumbnail, $image, 0, 0, 0, 0, $sizemin[0], $sizemin[1], $size[0], $size[1]); //resize and resample image
//chmod original file to 0777 temporarily, then return to 0644
if(!@chmod($path_server,0777))
if($config['debug_mode'] == 1) echo "Não foi possível alterar o chamod do diretório: ($path_server)";
@ImageDestroy($image); //free memory
if (!@ImagePNG($thumbnail, $path_thumb)) { // try to save thumbnail image
$msg .= "Não foi possível criar o thumbnail";
}
if(!@chmod($path_server, 0644))
if($config['debug_mode'] == 1) echo "Não foi possível alterar o chamod do diretório: ($path_server)";
return $msg;
}
//----------------------
//doItToBrowser()
//----------------------
function doItToBrowser($pic, $path, $width, $height, $quality, $smart_resize) {
//strip extension from value
//$bits = explode(".", substr($pic,-6,6)); $extension = $bits[1]; //get the extension
$bits = $this -> splitFilenameAndExtensionMirror($pic);
$type = $bits[1];
//first create a blank image
$size = getimagesize($path); //get width/height (path support from PHP 4.05)
if(strcasecmp($type, "jpeg") == 0 || strcasecmp($type, "jpg") == 0)
$image = imagecreatefromjpeg($path); //attempt to open original image
elseif(strcasecmp($type, "gif") == 0)
$image = imagecreatefromgif($path); //attempt to open original image
else
$image = imagecreatefrompng($path); //attempt to open original image
if($smart_resize == 1) {
//resize only if bigger than than the allowed thumbnail size
if($size[0]>$width || $size[1]>$height) {
if ($size[0]>=$size[1]) { //if width is greater than height or equal
$sizemin[0]=$width;
$sizemin[1]=$height;
}
if ($size[1]>$size[0]) { //if height is greater than width
$sizemin[0]=$height;
$sizemin[1]=$width;
}
}
else {
$sizemin[0]=$size[0];
$sizemin[1]=$size[1];
}
}
else {
$sizemin[0]=$width;
$sizemin[1]=$height;
}
$thumbnail = imagecreatetruecolor($sizemin[0],$sizemin[1]);
imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $sizemin[0], $sizemin[1], $size[0], $size[1]); //resize and resample image
header("Content-type: image/jpeg");
imagejpeg($thumbnail);
imagedestroy($thumbnail);
}
//----------------------
//splitFilenameAndExtensionMirror()
//----------------------
function splitFilenameAndExtensionMirror($filename) {
$str = strrev($filename);
$bits = explode(".",$str);
$extension = strrev($bits[0]);
$name = substr($filename,0,strlen($filename)-strlen($extension)-1);
$arrBits[0] = $name; $arrBits[1] = $extension;
return $arrBits;
}
}//end class
?>
III - Fico grato desde já, espero com a ajuda de vocês aprender mais e mais, flw
IV - Mil desculpas não sei proque meu poste ficou assim desconfigurado =D
Carregando comentários...