I spoke to soon, after days of thinking, I've figured it out...
This is what overloaded the server:
getimagesize($urlpic .$pic);
It was looking to get the image size from a folder, since $pic would equal nothing, so I just tried it right now, by adding a simple "if ($pic == "") {} else {" to the script...now it works perfect and doesn't overload the server!
If i make no sense, horray for me!