即使在0777目录中,也不能使用imagepng创建PNG图像


PNG image is not created with imagepng even inside a 0777 directory

Android应用程序中,我将photo发布到webserver中。在PHP脚本中,我想将文件保存在directory中:

$name = "parcelle_" . $photo->lireBienPhotoSeq() . ".png";
if ( ! file_exists (RP_PHOTO_PARCELLE) ) {
    mkdir(RP_PHOTO_PARCELLE, 0777, true);
    chmod(RP_PHOTO_PARCELLE, 0777);
}
$dest = DIR_MAIN . '/data/photo_parcelle/' . $name;
$image = base64_decode($_POST["image"]);
$img = imagecreatefromstring($image);
if ($img !== false)
    imagepng($img, $dest);
$chemin = PHOTO_PARCELLE . $name;

问题是image没有创建,Android应用程序收到响应代码500 (HTTP_INTERNAL_ERROR) !我做了一个ls -l查看directory的权限,是0777。

有几件事可能会出错,你的描述不够详细。

如何发布图像?

您确定它是作为POST变量发送的,而不是作为$_FILES中的上传文件发送的吗?

您确定$_POST['image']包含可识别的图像格式(JPEG、PNG、GIF、WBMP和GD2)的内容,而不是类似原始数据的内容吗?

您确定RP_PHOTO_PARCELLE与DIR_MAIN相同吗?‘/数据/photo_parcelle/’吗?

imagecreatefromstring($image)的结果是什么??

如果你直接调用脚本,你会让它执行还是出现500个错误?

查看日志后,imagecreatefromstring函数是未知的,所以安装了gd包,它可以工作!服务器是新的,不像我的本地电脑!lol