Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with getimagesize

Status
Not open for further replies.

dreammaker888

Programmer
Jul 31, 2007
44
US
I have the following code but $ImageSize returns empty.
What am I doing wrong?

Code:
$result = mysql_query($qdf)
	or die("<BR>Invalid query: $qdf <BR>" . mysql_error() . "".$result);

	$row = mysql_fetch_array($result);

	$pic = $row['PicURL'];
	$ImageSize = getimagesize($pic);


	echo $ImageSize[0];
	echo $ImageSize[1];	
	echo $ImageSize[2];
	echo $ImageSize[3];

Do I have to declared $ImageSize as array somewhere?

What exactly do each of the array should return 0, 1, 2, etc.? I am looking for the height and the width of the picture.

Thanks.
 
The array should contain something similar to the following if it can get the information from the file.

Code:
Array
(
    [0] => 60  [green]\\Width[/green]
    [1] => 60  [green]\\Height[/green]
    [2] => 1   [green]\\Image Type[/green]
    [3] => width="60" height="60" [green]\\String for HTML Image tag[/green]
    [bits] => 8 
    [channels] => 3
    [mime] => image/gif 
)

If its not retuning anything, perhaps it can't access the image.

What is in your $pic variable?

Is your $ImageSize variable returning FALSE?
You can check it like this:
Code:
if($ImageSize===FALSE)
{
echo "Its False";
}



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
You don't need to declare it. By just using the the function it should get declared and contain the values I posted.

So this is fine: $ImageSize = getimagesize($pic);

If you want to declare it:
$ImageSize=array(); should be enough.

Running getimagesize on the image URL you provided yields the following information for it:

Code:
Array
(
    [0] => 576
    [1] => 527
    [2] => 2
    [3] => width="576" height="527"
    [bits] => 8
    [channels] => 3
    [mime] => image/jpeg
)

So there must be something else wrong there. Now You may be getting an error you are unaware of.

Can you take a look at PHP's error log see if it has anythng relevant?

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Can you post the complete code that got you those result?

Thanks.

 
Sure, its nothing fancy:

Code:
$pic="[URL unfurl="true"]http://home.att.net/~DMK2/TriHead.jpg";[/URL]
$ImageSize=getimagesize($pic);
echo "<pre>";
print_r($ImageSize);
echo "</pre>";



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
you need to make sure that your system is set up to allow you to access foreign url's. it's in the php.ini file.
 
I put this in a php file and when I ran it it returned nothing.

What could be wrong?

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php

echo "xx<br>";
$pic="[URL unfurl="true"]http://home.att.net/~DMK2/TriHead.jpg";[/URL]
$ImageSize=getimagesize($pic);
echo "<pre>";
print_r($ImageSize);
echo "</pre>";

echo "yy";
?>
</body>
</html>
 
I may know why? It could be the encoding of the "~" in front of DMK.

The space is %20, what is the encoding for ~?

 
Actually, my hosting is having problem with the getimagesize function when the jpg file is residing in another server (in this case at att.net).

If I copy the file into the host server, the function worked and returned the proper array.

The problem I have is, it is impractical for me to copy the thousands of pictures from att.net onto my host.

Does anyone know how to solve this delimma?

 
Sorry, missed your post in the haste of testings.

This is new to me. Where is php.ini residing?
 
check the settings through a call to phpinfo()
 
As Jpadie suggested use a call to phpinfo(), and look for the entry for allow_url_fopen.

It must be set to on.

If its not set to on, you won't have access to remote urls.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
but you can try a local php.ini file. just create a text file with the relevant directive in it. save it as php.ini and upload it to the script directory in question. sometimes an ISP will allow overrides like these.
 
OK. I've got it.

Modified the ini file and everything works like charm.

Thank you, thank you, THANK YOU.

 
i suspect you would have got their earlier if your error display had been turned on. for debugging i would recommend that you include these lines at the start of your script
Code:
ini_set('error_display', 'ON');
error_reporting(E_ALL);

or change the relevant settings in php.ini
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top