我在 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 它。