Salve a tutti e grazie per l'eventuale risposta.
Il mio è un problema che mi affligge ormai da tempo, per cui passo subito alla spiegazione di questo infortunio.

Ho i seguenti files php denominati avatar.php,pagina.php e index.php
Dove in avatar.php ho delle funzioni la quale stabiliscono un Output per la pagina.php, in pratica il file pagina.php è un'immagine composta in GD.
(Dove in .htaccess ho una regola di Rewrite in immagine.jpg)

-> Quindi nel file pagina.php chiamo le funzioni di avatar.php
-> Nel file index.php ho [img]immagine.jpg[/img] dove però considerando il rewrite è come se fosse [img]pagina.php[/img]

Il mio problema principale riguarda il file avatar.php, in pratica in questa parte di codice dove desidero salvare il file nella directory "upload" oltre che a fare l'output :

codice:
	function output()
	{
		// If the filename is set, save it to a file 
		if(!empty($this->filename))
		{
			//notice that this function has the added $this->filename value (by setting this you are saving it to the hard drive)
			imagejpeg($this->canvas, $this->filename,100); 
		
		//Otherwise output to the header
		}else{
			//before you can output to the header, you must tell the browser to interpret this document 
			//as an image (specifically a jpeg image)

			header("content-type: image/jpeg"); 



			//Output, notice that I ommitted $this->filename
			imagejpeg($this->canvas, "", 100);
			imagejpeg($this->canvas, "upload/".$ir['username'].".jpg", 100); 


		}
		//Removes the image from the buffer and frees up memory
		imagedestroy($this->canvas); 	
	}
In pratica funge solo se non utilizzo $ir['username'], quindi se utilizzo ad esempio questo :
imagejpeg($this->canvas, "upload/newimage.jpg", 100);

Il file avatar.php ovviamente richiama la funzione del select e per la connessione al database MySQL.