views:

65

answers:

4

So, I have this code:

        } else {

            $photograph_moderation = new PhotographModeration($this->photograph_id);
            $photograph_moderation->purgePhotograph();

            //eventually take to an error page
            die('image is not big enough to upload');

        }

the purgePhotograph() function gets called properly when this condition is met, but the script never appears to die. Is there a reason why die wouldn't get called here? purgePhotograph() has no script killing commands either.

Here's the purge_photograph function:

public function purgePhotograph() {

    $db = Connect::connect();
    $photograph_id = $db->real_escape_string($this->photograph_id);

    $query = "SELECT * from photographs WHERE id='{$this->photograph_id}'";
    $result = $db->query($query);
    $photograph = $result->fetch_assoc();

    if ($photograph['location'])
    unlink($photograph['location']);

    if ($photograph['thumbnail_location'])
    unlink($photograph['thumbnail_location']);

    if ($photograph['watermark_location'])
    unlink($photograph['watermark_location']);

    if ($photograph['xsmall_location'])
    unlink($photograph['xsmall_location']);

    if ($photograph['small_location'])
    unlink($photograph['small_location']);

    if ($photograph['medium_location'])
    unlink($photograph['medium_location']);

    if ($photograph['large_location'])
    unlink($photograph['large_location']);

    if ($photograph['xlarge_location'])
    unlink($photograph['xlarge_location']);

    if ($photograph['xxlarge_location'])
    unlink($photograph['xxlarge_location']);

    if ($photograph['xxxlarge_location'])
    unlink($photograph['xxxlarge_location']);

    $query = "DELETE from photographs WHERE id='{$this->photograph_id}'";
    $result = $db->query($query);

    $query = "DELETE from photograph_tags WHERE photograph_id='{$this->photograph_id}'";
    $result = $db->query($query);

}
+2  A: 

Check if purgePhotograph() returns. Maybe it has a deadloop or takes really long time.

ZZ Coder
Or just comment it out and see if die works then. If so you know the issue is with `purgePhotograph()`
Josh
+1  A: 

Maybe now is the time to install a php debugger module and step into the code in question.
xdebug and e.g. netbeans as the frontend work well enough.

VolkerK
A: 

Try to put it into an try/catch block. Maybe something is throwing an exception before die can get executed.

Are you getting any error?

TheCandyMan666
+1  A: 

Wow, the problem was purgePhotograph() never had a return 1; at the end. I didn't know this was required for following lines to execute.

ThinkingInBits
"I didn't know this was required for following lines to execute." It isn't. Plenty of PHP built-in functions don't have a return statement (also referred to as returning `void` in the PHP manual) and execution continues normally. This is likely indicative of some other problem.
R. Bemrose
It's not required. There was some other problem that you must have inadvertently solved. BTW: Make sure to see my comment to the main thread...
ircmaxell
Statements are all completing properly, I just put them in conditionals and tested each one
ThinkingInBits
Have you checked the error log? Could it have been the WSOD (White Screen Of Death)?
ircmaxell