有人可以帮我将此代码转换为PHP 4吗?

try
{
  $picture = PDF_open_image_file($PDF, "jpeg", $imgFile, "", 0); // This is the original statement, this works on PHP4
}
catch(Exception $ex)
{
  $msg = "Error opening $imgFile for Product $row['Identifier']";
  throw new Exception($msg);
}

基本上,当发生致命错误时,我需要获取$ row ['Identifier'],以便知道导致此错误的产品。

提前致谢。

编辑:我不知道PHP_open_image_file是做什么的,但有时会出现如下错误,并且我需要获取导致错误的产品标识符。

最佳答案

我以为您使用的是pdflib PECL扩展名中的PDF_open_image_file()吗?

如果是这样,那么它将永远不会在PHP 4上引发异常。我会假设通过结果报告错误状态,该结果是一个int值,因此在出现错误的情况下可能

//try
if (file_exists($imgFile)) {
    $picture = PDF_open_image_file($PDF, "jpeg", $imgFile, "", 0);
}

//catch
if (!$picture) {
   $msg = "Error opening $imgFile for Product $row['Identifier']";
   print $msg;
}

已使用file_exists更新了,以防止发生致命错误。

作为附录的问题,为什么要尝试在PHP4上抛出异常?

10-08 16:31