Passing PHP variables trough functions?
        Posted  
        
            by 
                Mateus Nunes
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Mateus Nunes
        
        
        
        Published on 2012-04-06T23:17:06Z
        Indexed on 
            2012/04/06
            23:30 UTC
        
        
        Read the original article
        Hit count: 340
        
I'm facing some troubles to pass php variables value trough functions,every time i try to use a variable inside one of my functions its value becomes nil,let me be more specific.I have the following code in my php file:
$myvar = $Session['username'];
function updateuserinformation(){
        if(trim($_FILES["fileUpload"]["tmp_name"]) != ""){
            $images = $_FILES["fileUpload"]["tmp_name"];
            $new_images = "thumbnails_".$_FILES["fileUpload"]["name"];
            copy($_FILES["fileUpload"]["tmp_name"],"Photos/".$_FILES["fileUpload"]["name"]);
            $width=200; //*** Fix Width & Heigh (Autu caculate) ***//
            $size=GetimageSize($images);
            $height=round($width*$size[1]/$size[0]);
            $images_orig = ImageCreateFromJPEG($images);
            $photoX = ImagesX($images_orig);
            $photoY = ImagesY($images_orig);
            $images_fin = ImageCreateTrueColor($width, $height);
            ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width+1, $height+1, $photoX, $photoY);
            ImageJPEG($images_fin,"Photos/".$new_images);
            ImageDestroy($images_orig);
            ImageDestroy($images_fin);
            print $data["foo"];
            echo"$myvar";
            mysql_query("UPDATE users SET userpictureaddress = 'http://www.litsdevelopment.com/litsapplication/userimages/MATEUS' WHERE username = 'Mateus' ");
        }
}
I trying to use the $myvar value in my function but every time i run the code it just doesn't work,i've already tried global,globals,arrays and session for nothing worked.Of corse i'm making a little mistake in some part of it,but anyone know what is the correct way to do this?
© Stack Overflow or respective owner