PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
JellyFish
DevNet Resident
Posts: 1361 Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA
Post
by JellyFish » Sun Jan 14, 2007 3:28 pm
It's been a while sense I've been on php code forum. Been working on client stuff.
I get a php error:
Warning: Division by zero in "the url" on line 286
line 286:
Code: Select all
$newwidth = ($newwidth/$imgheight);
line 284 to 286:
Code: Select all
list($imgwidth, $imghieght) = getimagesize("Url");
$newwidth = (($imgwidth * 100));
$newwidth = ($newwidth/$imgheight);
I don't understand why the php parser is saying that ($newwidth/$imgheight) is division by 0??? It's clearly not zero at all.
According to my arithmetics it would work perfect. Unless I'm going wrong somewhere.
Last edited by
JellyFish on Sun Jan 14, 2007 4:33 pm, edited 1 time in total.
Kieran Huggins
DevNet Master
Posts: 3635 Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:
Post
by Kieran Huggins » Sun Jan 14, 2007 3:52 pm
http://www.php.net/manual/en/function.list.php
List assigns variables backwards, that is, from right to left.
getimagesize() returns an array of 4 elements. Since you're only collecting two, you're collecting the right-most two (type & attr).
This should work:
Code: Select all
list($imgwidth, $imgheight, $imgtype, $imgattr) = getimagesize("Url");
$newwidth = (($imgwidth * 100));
$newwidth = ($newwidth/$imgheight);
decipher
Forum Commoner
Posts: 38 Joined: Mon Mar 13, 2006 6:27 am
Location: south africa
Post
by decipher » Sun Jan 14, 2007 3:55 pm
and your spelling of $imgheight is different to variable you used in the list:
list($imgwidth, $imghieght)
JellyFish
DevNet Resident
Posts: 1361 Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA
Post
by JellyFish » Sun Jan 14, 2007 4:01 pm
Damn I feel stupid...
decipher
Forum Commoner
Posts: 38 Joined: Mon Mar 13, 2006 6:27 am
Location: south africa
Post
by decipher » Sun Jan 14, 2007 4:11 pm
trust the parser
JellyFish
DevNet Resident
Posts: 1361 Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA
Post
by JellyFish » Sun Jan 14, 2007 4:32 pm
Thanks guys. Post out.