小编Exp*_*0de的帖子

Laravel:将Base64 .png文件从控制器保存到公用文件夹

我通过Ajax将一个png图像文件发送到base64中的控制器.我已经测试并确定控制器已收到id但仍无法将其保存到公用文件夹.

这是我的控制器

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  );
}
Run Code Online (Sandbox Code Playgroud)

php laravel laravel-4

15
推荐指数
4
解决办法
5万
查看次数

标签 统计

laravel ×1

laravel-4 ×1

php ×1