0

我在 PHP 中编写了一个接受用户输入的页面,然后在传递这些参数后对 Perl 文件执行 shell_exec。

我的 Perl 文件基本上会生成一个 GD::Graph。当我第一次运行脚本时,似乎没有问题,并且我得到了一个有效的 image.gif 文件。但是,再次运行它不会更改 image.gif 文件中的任何数据。它保持不变,就好像它不能被覆盖一样。

然后我通过 shell 执行 Perl 脚本并手动传递参数。这是我收到的错误消息:

Failed to save graph to file: uploads/image.gif. Permission denied at image.pl line 178.

Perl中的相关代码是:

    my $bar_file = $filepath . '/image.gif';

    if (-e $bar_file) {
            #If file exists, delete
    unlink($bar_file);
    }
    else {
    print "File does not exist.";
    }

    open(IMG, ">$bar_file") 
      || die ("\nFailed to save graph to file: $bar_file. $!"); 

    binmode IMG; 
    print IMG $plot->gif(); 
    close IMG; 

有问题的第 178 行是:

open(IMG, ">$bar_file") 

我尝试将文件更改为 CHMOD 777,但由于它是由Apache生成的,我没有足够的权限来 CHMOD 它。

4

2 回答 2

0

你可以检查是否取消链接失败?成功时,它返回它成功删除的文件数。失败时,它返回 false 并设置 $! (错误)。

于 2010-11-10T15:59:25.427 回答
0

您确定要在 PHP 本身中使用 GD 挂钩吗?
http://php.net/manual/en/book.image.php

于 2010-11-10T21:17:46.300 回答