我通过Ajax向base64中的控制器发送png图像文件。我已经测试并确定控制器已收到ID,但仍无法将其保存到公用文件夹。Laravel:将Base64 .png文件保存到控制器的公用文件夹中
这里是我的控制器
public function postTest() {
$data = Input::all();
//get the base-64 from data
$base64_str = substr($data->base64_image, strpos($data->base64_image, ",")+1);
//decode base64 string
$image = base64_decode($base64_str);
$png_url = "product-".time().".png";
$path = public_path('img/designs/' . $png_url);
Image::make($image->getRealPath())->save($path);
// I've tried using
// $result = file_put_contents($path, $image);
// too but still not working
$response = array(
'status' => 'success',
);
return Response::json($response );
}
感谢您的回应!我总是这样使用public_path(),它的工作正常。我认为这个问题也是Input :: file方法。所以现在我放弃了使用它:P。检查我的答案! – Expl0de 2014-11-06 18:12:44
路径不是问题,也不是必需的,只有'$ path =“/ img/designs /”。 $ png_url'就够了。 – 2014-11-06 18:28:43