Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Division by zero error
Old 09-24-2007, 12:33 PM Division by zero error
pealo86's Avatar
Super Spam Talker

Posts: 876
Name: Matt Pealing
Location: England, north west
Trades: 0
My script for resizing images brings up loads of error messages! I cant figure out why?

Here are the errors:
Quote:
Warning: Division by zero in /var/www/inspindesign/test/upload.php on line 10

Warning: imagecreatetruecolor(): Invalid image dimensions in /var/www/inspindesign/test/upload.php on line 11

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /var/www/inspindesign/test/upload.php on line 13

Warning: imagejpeg(): supplied argument is not a valid Image resource in /var/www/inspindesign/test/upload.php on line 16

Warning: imagedestroy(): supplied argument is not a valid Image resource in /var/www/inspindesign/test/upload.php on line 18

Warning: imagedestroy(): supplied argument is not a valid Image resource in /var/www/inspindesign/test/upload.php on line 19
and here is my PHP code:
PHP Code:
<?php
include "../conn.php";

$upload=$_FILES['upload']['tmp_name'];
list(
$width$height)=getimagesize($upload);

echo 
$width.$height;

$newWidth=150;
$newHeight=($height/width)*150;
$tmp=imagecreatetruecolor($newWidth$newHeight);

imagecopyresampled($tmp$src0000$newWidth$newHeight$width$height);
$target='images/'.$_FILES['upload']['tmp_name'];

imagejpeg($tmp$filename100);

imagedestroy($src);
imagedestroy($tmp);

?>
Can anyone see what is wrong with it? I think its all down to the division on line 10, but I dont see how its different to any other division?
__________________

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
 
Register now for full access!
Old 09-24-2007, 12:49 PM Re: Division by zero error
maxxximus's Avatar
Extreme Talker

Posts: 219
Name: Rob
Location: UK
Trades: 0
Division by zero error is your attempting to divide $height a number by width a string - should of course be the variable $width.
maxxximus is offline
Reply With Quote
View Public Profile
 
Old 09-24-2007, 01:40 PM Re: Division by zero error
pealo86's Avatar
Super Spam Talker

Posts: 876
Name: Matt Pealing
Location: England, north west
Trades: 0
Ahhhh i cant believe I didnt notice that, thanks!

there were a couple of errors that prevented it from working [that Ive fixed], but now Im presented with the text below:
Quote:
�JFIF�������<9u� />*~7*5_/ ֒i6*ƯůV,.,h-5=-<ǩ|C׋<ͥxzdZivzWw'Jɦi7 Ϩ+�:e/c)Z} HU||]l=:t*fԖxFXt%'Ze8IYRwÜ[םlK)8EJT-J5NqeK0c%chEIuQoj6}]LJ5 {ńz*o~j7U mH/-f7�'j뺇nP[^/w^ ֓Z_EN]FDk#$ })(HjUkSxYahړkOil*nm X$[hcsl)k+k[:D~;ũ kZ*Zߵkh4 {de4rA2?W qK5wq5o%ь^5N,FEiϖ)p*I TqSPVpU8->SJt+Rסʮ *NЯVs*0V9Ƥښ3;DKvW,x[ +\EyiC' ]'%.f(%*� thDi 0Prx@B%]4jX ?W-o?oIKK[mI{V:WwQӾ�1vM}oQ�f Ś:u_f#Ha*-V/]KFtC>}/X,5Ln]8,F/I>Ʈ7*MX0UeaOhxMy:ֵ ~ϖ n4Q q~mÚI.F= ?w H$|M#lw�{#G^?j 8t9+ Cɮh#~7n[?x–$-t?piM{O X͜=bX$X*MVs &' jp.iT*>hERr'*(SڔQS*aKcZJ "."FWyiR:t(mSq3$ �=Gz~ٞ)oG,#=j j8\c\Îp8�O_#dڏ}K: k}[i~#Kų[iNpjWۢI=5c+:`l؜qzxҎ &}eΓep aQTU%*2*S.+p[wC_m05v#Ökf((Jyf*7 '#Q�ל}{!�}_'=?,|'�0? !c'Θ|)pt�hXwN1W/}Ϣ:\V_:[xv7ץב̷x:~(?Ou!4y7|M� P�+f>[8s:|4�'�aq(}ZJ]l]?G?R??'}�{Oh�<ip k53#P'Mƥ\P֗5ڴ_ ?ϊ1{/:O GVŷ^!Ҧ7ngk24!&TcT֏ DM]7VZV *ݤAijvh K+kA;~ON;#1WLvuLj3:�Y )Pq8QN 1m P˲65`r-haq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T)`:4r*ii t0e:?a/>,ӄb1?:g
Ive never seen anything like this before??

Here is my new code:
PHP Code:
<?php
include "../conn.php";

$upload=$_FILES['upload']['tmp_name'];
$src=imagecreatefromjpeg($upload);
list(
$width,$height)=getimagesize($upload);


$newWidth=150;
$newHeight=($height/$width)*150;
$tmp=imagecreatetruecolor($newWidth$newHeight);

imagecopyresampled($tmp$src0000$newWidth$newHeight$width$height);
$target='images/'.$_FILES['upload']['tmp_name'];

imagejpeg($tmp$filename100);

imagedestroy($src);
imagedestroy($tmp);

?>
__________________

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
Old 09-24-2007, 02:04 PM Re: Division by zero error
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
I see the error, on line 10 your missing a $. I best also point out that you cannot divide by 0.

PHP Code:
<?php
include "../conn.php";

$upload=$_FILES['upload']['tmp_name'];
list(
$width$height)=getimagesize($upload);

echo 
$width.$height;

$newWidth=150;
// this is line 10.
// $newHeight=($height/width)*150; - it's diving ($height/width). It's missing the $
// change it to.
$newHeight=($height/$width)*150

$tmp=imagecreatetruecolor($newWidth$newHeight);

imagecopyresampled($tmp$src0000$newWidth$newHeight$width$height);
$target='images/'.$_FILES['upload']['tmp_name'];

imagejpeg($tmp$filename100);

imagedestroy($src);
imagedestroy($tmp);

?>
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE

Last edited by rogem002; 09-24-2007 at 02:06 PM..
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 09-24-2007, 02:59 PM Re: Division by zero error
pealo86's Avatar
Super Spam Talker

Posts: 876
Name: Matt Pealing
Location: England, north west
Trades: 0
Yeah thats what maxxximus pointed out so I fixed it. But the new error is what is in my post above yours
__________________

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
Old 09-24-2007, 03:16 PM Re: Division by zero error
Ultra Talker

Posts: 483
Trades: 0
I'm going to guess that the problem is that the browser doesn't know what the data that is being sent is meant to be. If you called the PHP script as an image source (eg. <img src="thisscript.php">) then it would have a clue, but at the moment it has none.

Instead you need to tell it what the data is explicitly. You can do this by sending headers such as:
header('Content-type: image/jpg');
header('Content-Length: ' . strlen($tmp));

or something similar. This also assumes you haven't done anything silly like sent whitespace in your include files or some such thing.
__________________

Please login or register to view this content. Registration is FREE
TwistMyArm is offline
Reply With Quote
View Public Profile
 
Old 09-26-2007, 09:47 AM Re: Division by zero error
pealo86's Avatar
Super Spam Talker

Posts: 876
Name: Matt Pealing
Location: England, north west
Trades: 0
Hmmm I tried adding
PHP Code:
     header('Content-type: image/jpg'); 
after the include statement, and it just presented me the URL of the page?

Ive tried the original script I was using but now I get this!

Quote:
Warning: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error: in /var/www/inspindesign/test/upload.php on line 5

Warning: imagecreatefromjpeg(): '/tmp/phpXlZf7c' is not a valid JPEG file in /var/www/inspindesign/test/upload.php on line 5

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /var/www/inspindesign/test/upload.php on line 13
�JFIF�������
Warning: imagedestroy(): supplied argument is not a valid Image resource in /var/www/inspindesign/test/upload.php on line 18
Could it be that the server I have doesnt properly support the GD library? It is a free PHP server afterall.
__________________

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
Old 09-26-2007, 09:58 AM Re: Division by zero error
Novice Talker

Posts: 5
Name: Daniel Vojt
Trades: 0
Based on the error messages you received, it looks like GD library is supported on your server - those specific messages are kicked out by the GD library functions. It looks like the file you tried to upload for resizing isn't recognized as a JPG... is it?
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
mediatriks is offline
Reply With Quote
View Public Profile
 
Old 09-26-2007, 10:05 AM Re: Division by zero error
Ultra Talker

Posts: 483
Trades: 0
mediatriks is right... it could also be that your upload got truncated for some reason (eg. trying to upload more data than the server allows) or maybe it's a permissions thing?
__________________

Please login or register to view this content. Registration is FREE
TwistMyArm is offline
Reply With Quote
View Public Profile
 
Old 09-26-2007, 10:23 AM Re: Division by zero error
pealo86's Avatar
Super Spam Talker

Posts: 876
Name: Matt Pealing
Location: England, north west
Trades: 0
I dont think so, I tried setting the permissions on the folder as 777 and still it doesnt work

Also I checked with phpinfo() and post_max_size is set to 8M and upload_max_filesize is set to 2M, the image file is roundabout 200K
__________________

Please login or register to view this content. Registration is FREE
pealo86 is offline
Reply With Quote
View Public Profile Visit pealo86's homepage!
 
Old 09-26-2007, 10:38 AM Re: Division by zero error
Ultra Talker

Posts: 483
Trades: 0
Bizarre. Well, I'm out of ideas. Until you get that sorted out there's no real point in trying to understand what's wrong with the other script, as far as I can see...
__________________

Please login or register to view this content. Registration is FREE
TwistMyArm is offline
Reply With Quote
View Public Profile
 
Old 09-26-2007, 11:13 AM Re: Division by zero error
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
I think that as there is an error in the image, a variable like $height or $width might be null, and dividing something by null, in php means division by 0...

But maybe you should verify that your file is really uploaded, otherwise, an getimagesize() of a non-existant file will get you $height and $width = null
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 09-26-2007 at 11:15 AM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 09-26-2007, 12:32 PM Re: Division by zero error
Ultra Talker

Posts: 483
Trades: 0
Oh one other thing that I thought of!

Instead of trying to use the uploaded file in those image functions, read the contents into a string and print it out. If those contents are empty or something, it may very well be to do with your form. I spent literally at least 2 weeks trying to get one of my image uploader forms to work when I found out that you needed your form to have 'enctype="multipart/form-data"' added in the opening form tag.

So that might be the problem, too.
__________________

Please login or register to view this content. Registration is FREE
TwistMyArm is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Division by zero error
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.56286 seconds with 12 queries