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
경로는 문제가 아니며 필수 경로도 아니며'$ path = "/ img/designs /"만 필요합니다. $ png_url'이면 충분합니다. –