Codeigniter에서 jQuery Coppie[잘라내기 및 저장] 이미지 사용하기 - 한 걸음 한 걸음

오늘, 업로드하기 전에 jQuery croppie와ajax를 사용하여 재단된 그림을 보여 드리겠습니다.Codeigniter의 데이터베이스에 업로드하기 전에 이미지 크기를 잘라내고 조정하는 것을 보여 줍니다.
이 자습서에서는 PHP의 자르기 이미지를 학습합니다.이 자습서는 Codeigniter 4 프로젝트에서 jQuery와 aax를 사용하여 이미지를 업로드합니다.이미지는 Ajax를 사용하여 데이터베이스에 저장하기 전에 이미지 크기를 자르고 조정하는 미리 보기를 표시합니다.CodeIgniter 프로젝트의 웹 페이지를 새로 고치거나 다시 로드할 필요가 없습니다.
<?php namespace App\Controllers;

use CodeIgniter\Controller;

class CropImageUpload extends Controller
{
    public function index()
    {    
         return view('crop-image-upload-form');
    }

    public function store()
    {  
           helper(['form', 'url']);

           $db    = \Config\Database::connect();
         $builder = $db->table('crop_images');


         $data = $_POST["image"];

         $image_array_1 = explode(";", $data);

         $image_array_2 = explode(",", $image_array_1[1]);

         $data = base64_decode($image_array_2[1]);

         $imageName = time() . '.png';

         file_put_contents($imageName, $data);

         $image_file = addslashes(file_get_contents($imageName));

         $save = $builder->insert(['title' =>  $image_file]);

         $response = [
          'success' => true,
          'data' => $save,
          'msg' => "Crop Image has been uploaded successfully in codeigniter"
         ];


       return $this->response->setJSON($response);

    }
}

[Crop and Save] Image using jQuery Coppie in Codeigniter

좋은 웹페이지 즐겨찾기