为什么 PHP GD 库无法在我的磁盘上写入图像


Why PHP GD library fails to write images on my disk?

我写了一段像这样的php(test.php)代码

$width = 300;
$height = 200;
$im = imagecreatetruecolor($width,$height);
$mypic = imagecolorallocate($im,100,30,125);
imagefill($im,0,0,$mypic);
imagepng($im,'./mypic.png');
imagepng($im);
imagedestroy($im);

当我在 Ubuntu 命令行(php test.php)上运行它时,它工作正常并在我的磁盘上写入 mypic.png。但是,当我在远程客户端 (Chrome) 上访问 test.php 时,它会正确显示图片,但程序无法在我的磁盘上写入图像。

尝试运行chown -R www-data:www-data /var/www假设/var/www/是您的网站目录。或者使您正在写入的文件具有写入权限。