Edit: No me habia dado cuenta que habia un subforo especialido para las clases en PHP. Por favor si pudieran moverlo y perdon por las molestias :(.
Edit 2:
Con todas las pruebas , en una quite la instancia del objeto, lo he puesto pero me sigue dando el mismo error.
Tambien he modificado el codigo cambiando rectificando algunas cosas que habia cambiado para probar.
Buenas!
Despues de trastear medianamente con PhP durante un tiempo, estoy intentando hacer un "mini" CMS probando cosas con las que aun no me habia metido, entre ellas, las clases.
Estoy haciendo una clase para el tratamiento de imagenes, subida,etc..
Código:
class img{
var $width=''; // ANCHO DE LA IMAGEN QUE VA A SER TRATADA
var $height=''; //ALTO DE LA IMAGEN QUE VA A SER TRATADA
var $img=''; // IMAGEN
var $imgPath='images/';
var $imgTemp=''; //IMAGEN COPIA PARA LA SUBIDA AL SERVIDOR
var $imgType=''; //EXTENSION DE LA IMAGEN
var $imgSize=''; //TAMAÑO EN BYTES DE LA IMAGEN
var $error='';
var $imgNewX=''; //ANCHO DEL THUMB
var $imgNewY=''; //ALTO DEL THUMB
var $thumb='';
var $thumbPath='thumbs/';
function setImg($var){
$this->img=$var+$var;
echo $this->img;
//$this->img=$_FILES['imagen']['name'];
//$this->imgTemp=$_FILES['imagen']['tmp_name'];
//$this->imgType=$_FILES['imagen']['type'];
//$this->imgSize=$_FILES['imagen']['size'];
}
function imgY(){
$this->height=imagesy($this->img);
}
function imgX(){
$this->width=imagesx($this->img);
}
function imgCheck(){
if(!(strpos($this->imgType,"gif") || strpos($this->imgType,"jpeg") || strpos($this->imgType,"png"))){
echo $this->error="La imagen debe tener como extension : JPEG, GIF, PNG.";
return false;
}
if($this->imgSize>200000){
echo $this->error="La imagen no puede exceder el tamaño de 200Kb";
return false;
}
}
function imgUpload(){
if(!move_uploaded_file($this->imgTemp,$this->imgPath.$this->img)){
echo $this->error="No se pudo realizar la subida al servidor... Int$eacute;ntelo pasado unos minutos";
return false;
}
}
function imgResize($y){
$this->imgNewX=(imgX() * ($y/imgY()));
$this->imgNewY=$y;
$this->thumb=imagecreatetruecolor($this->imgNewX,$this->imgNewY);
imagecopyresized($this->thumb,$this->img,0,0,0,0,$this->imgNewX,$this->newY);
if(strpos($this->imgType,"gif")){
imagegif($this->thumb, $this->thumbPath.$this->img);
}else if(strpos($this->imgType,"jpeg")){
imagejpeg($this->thumb, $this->thumbPath.$this->img);
}else imagepng($this->thumb, $this->thumbPath.$this->img);
}
}//FIN DE CLASE
En el otro archivo tengo esto que se me olvido ponerlo , ahora estoy haciendo pruebas asi que no es el real:
Código:
include("imageClass.php");
$pepe=new img;
$var=4;
$img->setImg($var);
Me da el siguiente error: Call to a member function setImg() on a non-object (
Editado : antes me daba otro por estar en la parra por el edit que puse arriba)
Aun me lio muchisimo con las clases a la hora de definirlas y aprovechar el uso de sus funciones para el resto del codigo. Normalmente habia trabado con webs modulares , y no aprovechaba tanto el codigo como pretendo ahora.
Espero puedan ayudarme porque he mirado sobre las clases , incluso buscado clases similares , pero solo encuentro de tratamiento de imagenes no de subida.