2010-05-21 177 views
2

所以,我有这样的代码:与模具PHP的问题()

 } 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'); 

     } 

的purgePhotograph()函数被调用时,适当满足此条件,但该脚本永远不会出现死。死亡是不是有理由在这里召唤? purgePhotograph()也没有脚本查杀命令。

这里的purge_photograph功能:

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); 

} 
+1

你真的试过了,只是提供了三条线,没有'最终'在两者之间? – Anthony 2010-05-21 19:59:12

+0

我从来没有见过die()失败。是什么让你如此确信purgePhotograph()曾经退出? – timdev 2010-05-21 19:59:47

+0

@Anthony:我认为这是一个TODO评论,因为它最终会用一个错误页面代替'die' :-) – Josh 2010-05-21 20:00:35

回答

2

检查purgePhotograph()返回。也许它有一个死循环或需要很长时间。

+0

或者只是将其注释掉,然后查看是否有效。如果是这样,你知道问题是'purgePhotograph()' – Josh 2010-05-21 20:01:24

0

尝试将其放入try/catch块。 也许有些东西在死亡可以执行之前抛出异常。

您是否收到任何错误?

1

哇,问题是purgePhotograph()从来没有一个返回1;最后。我不知道这是执行以下行所必需的。

+0

“我不知道这是执行下面的行需要。”事实并非如此。大量的PHP内置函数没有返回语句(在PHP手册中也被称为返回'void'),并且执行正常继续。这可能表明其他一些问题。 – Powerlord 2010-05-21 20:08:47

+1

这不是必需的。还有一些其他问题你必须无意中解决。顺便说一句:请务必看到我的意见主线程... – ircmaxell 2010-05-21 20:08:58

+0

声明都完成正确,我只是把它们在条件和测试每一个 – ThinkingInBits 2010-05-21 20:23:29