PHP code example of jonexyz / wang-editor-v4

1. Go to this page and download the library: Download jonexyz/wang-editor-v4 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jonexyz / wang-editor-v4 example snippets




namespace App\Admin\Controllers;

use Illuminate\Http\Request;
use Encore\Admin\Controllers\AdminController;

class CommonController extends AdminController
{
    public function upload(Request $request)
    {
        $type = $request->get('type');

        $dir_path = 'uploads/' . config('admin.upload.directory.image'); // 文件存储路径
        $rule = ['jpg', 'png', 'gif']; //允许的图片后缀


        if ($request->hasFile('images')) {

            $files = $request->file('images'); //接前台图片

            $path = [];
            foreach ($files as $file) {

                $clientName = $file->getClientOriginalName();
                // $tmpName = $file->getFileName();
                // $realPath = $file->getRealPath();
                $size = $file->getSize();
                $entension = $file->getClientOriginalExtension();
                if (!in_array($entension, $rule)) {
                    continue;
                }
                $newName = md5(date("Y-m-d H:i:s") . $clientName) . "." . $entension;
                $path[] = [
                    'path' => $file->move($dir_path, $newName),
                    'file_name' => $clientName,
                    'size' => $size
                ];
                //$namePath = $url_path . '/' . $newName;
                //return $path;

            }

            $insert_data = [];
            foreach ($path as $p) {
                $file_path = str_replace("\\", "/", $p['path']->getPathname());
                $data[] = config('APP.URL') . '/' . $file_path;
                $insert_data[] = [
                    'file_name' => $p['file_name'],
                    'path' => $file_path,
                    'size' => $p['size'],
                    'created_at' => date('Y-m-d H:i:s'),
                    'updated_at' => date('Y-m-d H:i:s')
                ];
            }


            return $res = ['errno' => 0, 'data' => $data];
        }

    }
}