Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts

    display data from func

    hi guys

    need a little guidance, i've ome up with:
    PHP Code:
        function getImageInfo($file) {
            
    $info getimagesize($file);
            
    $filesize filesize($file);
            return array(
                
    'width'        => intval($info[0]),
                
    'height'    => intval($info[1]),
                
    'bytes'        => intval($filesize),
                
    'size'        => format_bytes($filesize),
                
    'mime'        => $info['mime'],
                
    'html'        => 'width="'.$info[0].'" height="'.$info[1].'"'
                
    //'bits' => $info['bits'],
                //'channels' => $info['channels'],
            
    );
        } 
    i'm wandering what options i have to display, eg. filesize..?

  • #2
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts
    i've just done this
    PHP Code:
        function showInfo($url) {
            
    $showIt getImageInfo($url);
            
             
        } 
    then in display.php im doing:
    PHP Code:
    echo $showIt['size']; 
    no data shows....

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    And a var_dump($showIt); results in what?

  • #4
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts
    var_dump($showIt); results in NULL.

  • #5
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,535
    Thanks
    45
    Thanked 259 Times in 256 Posts
    You're sure the file path is right? echoing $file shows the right value?

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    No, the problem here is that the function you are calling is not what you have posted here. If that results in null, then you have not returned anything at all from the function. Even if the calls to getimagesize or filesize fail, that function still returns an explicit array which would give you results like so:
    Code:
    array(6) { ["width"]=> int(0) ["height"]=> int(0) ["bytes"]=> int(0) ["size"]=> NULL ["mime"]=> NULL ["html"]=> string(18) "width="" height=""" }

  • #7
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts
    My uplooad func is in funcs.php, no calls to the getImageInfo(), should there be?

    This is in my template.func.php, ok?
    PHP Code:
        function showInfo($url) {
            
    $showIt getImageInfo($url);
            
        } 
    Should i even pass anything to the func above?

    then in display.php im doing:
    PHP Code:
    echo $showIt['size']; 

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You're going to need to do some tracing. All I'm saying is that if you have this:
    PHP Code:
        function getImageInfo($file) {
            
    $info getimagesize($file);
            
    $filesize filesize($file);
            return array(
                
    'width'        => intval($info[0]),
                
    'height'    => intval($info[1]),
                
    'bytes'        => intval($filesize),
                
    'size'        => format_bytes($filesize),
                
    'mime'        => $info['mime'],
                
    'html'        => 'width="'.$info[0].'" height="'.$info[1].'"'
                
    //'bits' => $info['bits'],
                //'channels' => $info['channels'],
            
    );
        }  

    // ... somewhere else
    $io getImageInfo($sPath);
    var_dump($io); 
    And it says its null, then getImageInfo isn't the one you are calling as its impossible for the $io in this example to ever be null from the getImageInfo in this example. That indicates that without a fatal error, you have a different function called getImageInfo that has a void return.

  • #9
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts
    I'm sorry m8, when you said do var_dump($file); I thought to do it in display.php.... Doh, anyway just did it inside the show func and it's showing the info........ now is there a way to pull the info outside the func>?

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Not interesting in a var dump inside the function; even if it fails the results will still be that of the array structure provided. If it shows as null on the results of a function call, then that function is not what you are actually calling.

  • #11
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,535
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Have the function return the array? Or whatever information you want? But if you're doing that and you're passing the filename from outside, why not just run the PHP functions outside?

  • #12
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts
    Keleth, I did that at 1st, but then thought if there's better way, more practical then try it...

    Fou-Lu, to do it outside i'd need: $x = showFunc($file); echo $x['size'];

    Maybe an obvious answer?

  • #13
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    That's fine. But if this:
    PHP Code:
    $x showfunc($file);
    var_dump($x); 
    returns:
    Code:
    NULL
    Then showFunc isn't returning a result, which means it does not match what you have here which explicitly returns an array.

  • Users who have thanked Fou-Lu for this post:

    Chris-2k (07-31-2012)

  • #14
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts
    hey Fou-lu, Your rite, so why can i only pull the info withinside the showFunc func?

  • #15
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Well I guess that depends what's in the function showFunc since you haven't posted that here.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •