带有XAMPP的OSX:“ imagegd2():无法打开临时文件”

sun*_*nzu 2 php macos gd2 tmp

当我转到使用imagegd2()生成的图像URL时,出现“ imagegd2():无法打开临时文件”错误消息:

$image->make($data['path']);
$image->resize(100, null, true)->crop(70, 70);
// create response and add formated image
$response = Response::make($image->encode('png'));
// set content-type
$response->header('Content-Type', 'image/png');
Run Code Online (Sandbox Code Playgroud)

它与权限和OSX有关,因为在Linux dev环境中可以正常工作。

sun*_*nzu 5

我发现了问题,Mac OSx临时文件夹类似于:/ var / folders / 6l / zy7_vl5n5kq8wbv00bvzc15h0000gn / T /

在终端中检查您的临时文件夹:

echo $TMPDIR
Run Code Online (Sandbox Code Playgroud)

授予该文件夹的读取,写入和执行权限或777,而不仅仅是755:

chmod -R 777 [your_tmp_folder]
Run Code Online (Sandbox Code Playgroud)

就这样!