...

View Full Version : display data from func



Chris-2k
07-29-2012, 08:10 PM
hi guys

need a little guidance, i've ome up with:

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..?

Chris-2k
07-29-2012, 10:39 PM
i've just done this
function showInfo($url) {
$showIt = getImageInfo($url);


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

no data shows....

Fou-Lu
07-30-2012, 02:20 PM
And a var_dump($showIt); results in what?

Chris-2k
07-30-2012, 03:29 PM
var_dump($showIt); results in NULL.

Keleth
07-30-2012, 03:34 PM
You're sure the file path is right? echoing $file shows the right value?

Fou-Lu
07-30-2012, 04:11 PM
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:


array(6) { ["width"]=> int(0) ["height"]=> int(0) ["bytes"]=> int(0) ["size"]=> NULL ["mime"]=> NULL ["html"]=> string(18) "width="" height=""" }

Chris-2k
07-30-2012, 04:31 PM
My uplooad func is in funcs.php, no calls to the getImageInfo(), should there be?

This is in my template.func.php, ok?

function showInfo($url) {
$showIt = getImageInfo($url);

}


Should i even pass anything to the func above?

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

Fou-Lu
07-30-2012, 08:02 PM
You're going to need to do some tracing. All I'm saying is that if you have this:


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.

Chris-2k
07-30-2012, 10:18 PM
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>?

Fou-Lu
07-30-2012, 10:21 PM
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.

Keleth
07-30-2012, 10:21 PM
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?

Chris-2k
07-30-2012, 10:36 PM
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?

Fou-Lu
07-30-2012, 11:30 PM
That's fine. But if this:


$x = showfunc($file);
var_dump($x);

returns:


NULL

Then showFunc isn't returning a result, which means it does not match what you have here which explicitly returns an array.

Chris-2k
07-31-2012, 01:30 PM
hey Fou-lu, Your rite, so why can i only pull the info withinside the showFunc func?

Fou-Lu
07-31-2012, 02:49 PM
Well I guess that depends what's in the function showFunc since you haven't posted that here.

Chris-2k
07-31-2012, 07:56 PM
I did mate, post #5.

Fou-Lu
08-01-2012, 12:11 AM
I don't see code in post #5. That's Keleth's post anyway.
Are you talking about this showInfo function? If so, then that's easy; it doesn't return a result.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum