Uploading Images

The Below code is what i am using to upload and resize images. now i have tried uploading 2 images one of them was 300 x 300 and another was 200 x 200 and neither uploaded it cam up with an error saying it was divsion by 0 :S can anyone see why?