doujiexi1824 2014-12-11 11:06
浏览 198

PHP无法打开ghostscript生成的文件

I have a small php function which uses ghostscript to take a multipage pdf and convert it to multiple pngs. This part of the script works perefctly i can run it and check the images folder and they are all there.

The next part of the script resizes the pngs produced by ghostcript. However any attempt to make use of these pngs in php results in "failed to open stream: No such file or directory"

Moreover if copy one of the generated pngs to another folder or even the same folder it will become readable. This leads me to believe the ghostscript generated images might have the incorrect permissions. But when i run my script to check for permissions and if the file exists. both return false.

Here is the conversion script:

    <?php
 //Upload pdf convert to pngs in the folder jpgs/originals
$uploaddir = 'uploadtemp/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo "<p>";
 if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {

    exec('bin\gswin32c.exe -o jpgs\originals\%3d.png -sDEVICE=png16m -r150 uploadtemp\input.pdf');
    unlink('uploadtemp\input.pdf');
    header('Location: main.php');
    } else {
    echo "Upload failed";
}       
?>

Here is the script which tries to call the now generated pngs:

 <?php
$filename = "jpgs/originals/1.png";

    if (is_writable($filename)) {
        echo 'The file is writable';
    } else {
        echo 'The file is not writable';
    }

    if (file_exists($filename)) {
        echo "The file $filename exists";
    } else {
        echo "The file $filename does not exist";
?>

Both if statements return false even though i can see the files generated in the folder

  • 写回答

1条回答 默认 最新

  • donglaoping9702 2014-12-11 12:52
    关注

    This is certainly a weird problem, when running the ghostscript parameter :jpgs\originals\%3d.png it creates files with 2 spaces in front of the digit. So calling the file 2.png doesn't work because it doesn't exist but if you call [space][space]2.png it works! And when windows copies the file it must erase the extra spaces or something.

    评论

报告相同问题?

悬赏问题

  • ¥15 蓝桥oj3931,请问我错在哪里
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染