尊龙凯时人生就是搏

ÔõÑùÔÚThinkPHP6ÖоÙÐи»Îı¾±à¼­Æ÷ͼƬÉÏ´«²Ù×÷£¿

thinkphp6×÷Ϊһ¿îÓÅÒìµÄphp¿ò¼Ü  £¬ÌṩÁ˸»ºñµÄ²Ù×÷Àà¿âºÍ¹¤¾ß  £¬Ê¹µÃ¿ª·¢Õß¿ÉÒÔ¸ü¿ì½ÝµØʵÏÖ¹¦Ð§ÐèÇó¡£ÔÚÍøÒ³¿ª·¢ÖÐ  £¬¸»Îı¾±à¼­Æ÷³£×÷Ϊ±Ø±¸¹¤¾ßÖ®Ò»  £¬¿ÉÒÔ×ÊÖúÓû§¸üÀû±ãµØ±à¼­ÄÚÈÝ¡£È»¶ø  £¬µ±Óû§ÏëÒª²åÈëͼƬʱ  £¬¾ÍÐèÒªÓÐͼƬÉÏ´«¹¦Ð§Ö§³Ö¡£

±¾ÎĽ«ÒÔUMEditor×÷ΪʾÀý  £¬ÏÈÈÝÔÚThinkPHP6ÖÐÔõÑùʵÏÖ¸»Îı¾±à¼­Æ÷ͼƬÉÏ´«¹¦Ð§¡£

µÚÒ»²½£ºÒýÈëUMEditor

½«UMEditorµÄ×ÊÔ´Îļþ£¨°üÀ¨js¡¢css¡¢imagesµÈ£©·Åµ½ÏîĿĿ¼ÏµÄpublicĿ¼ÖÐ  £¬È»ºóÔÚHTMLÒ³ÃæÖÐÒýÈëUMEditorµÄÏà¹Ø×ÊÔ´Îļþ¡£Ê¾ÀýÈçÏ£º

<!-- ÒýÈëUMEditor -->
<link href="/public/UMEditor/themes/default/css/umeditor.css" rel="stylesheet">
<script src="/public/UMEditor/umeditor.config.js"></script>
<script src="/public/UMEditor/umeditor.min.js"></script>

µÇ¼ºó¸´ÖÆ

µÚ¶þ²½£º±àдͼƬÉÏ´«½Ó¿Ú

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡± £»

ÔÚThinkPHP6ÖÐ  £¬¿ÉÒÔͨ¹ýRouteÀàºÍControllerÀàÀ´ÊµÏֽӿڵıàд¡£

ÔÚroutesĿ¼Ï½¨ÉèÒ»¸öupload.phpÎļþ  £¬´úÂëÈçÏ£º

<?php
use thinkacadeRoute;

Route::post('upload/image', 'api/Upload/uploadImage');

µÇ¼ºó¸´ÖÆ

¸Ã·ÓÉÓ³ÉäµÄ¿ØÖÆÆ÷ÒªÁìΪUpload¿ØÖÆÆ÷µÄuploadImageÒªÁì¡£

ÔÚappĿ¼Ï½¨ÉèÒ»¸öapiĿ¼  £¬È»ºóÔÚapiĿ¼Ï½¨ÉèÒ»¸öUpload¿ØÖÆÆ÷ºÍÒ»¸öUploadServiceЧÀÍ  £¬´úÂëÈçÏ£º

Upload¿ØÖÆÆ÷£º

<?php
namespace apppicontroller;

use apppiserviceUploadService;
use thinkacadeRequest;

class Upload
{
    public function uploadImage()
    {
        $file = Request::file('upfile');
        $uploadService = new UploadService();
        $result = $uploadService->uploadImage($file);
        return json($result);
    }
}

µÇ¼ºó¸´ÖÆ

UploadServiceЧÀÍ£º

<?php
namespace apppiservice;

use thinkacadeFilesystem;
use thinkacadeConfig;

class UploadService
{
    public function uploadImage($file)
    {
        $storage = Config::get('filesystem.default');
        $savename = Filesystem::disk($storage)->putFile('images', $file);
        $url = Config::get("filesystem.disks.{$storage}.url") . '/' . str_replace('\', '/', $savename);
        return [
            'state' => 'SUCCESS',
            'url' => $url,
            'title' => '',
            'original' => $file->getOriginalName(),
            'type' => $file->getOriginalExtension(),
            'size' => $file->getSize(),
        ];
    }
}

µÇ¼ºó¸´ÖÆ

ÔÚUploadServiceÖÐ  £¬ÎÒÃÇʹÓÃÁËThinkPHP6ÌṩµÄÎļþ´æ´¢¹¦Ð§  £¬ÒÔµÖ´ïͼƬÉÏ´«µÄÄ¿µÄ¡£ÏêϸʵÏÖʹÓÃÁËFilesystemÀàºÍConfigÀà¡£ÔÚÉèÖÃÎļþconfig/filesystem.phpÖÐ  £¬ÐèÒªÉèÖÃÏìÓ¦µÄ´æ´¢·½·¨ºÍ·¾¶¡£

µÚÈý²½£ºÉèÖÃUMEditor

ÔÚHTMLÒ³ÃæÖÐʵÀý»¯UMEditor  £¬²¢ÉèÖÃͼƬÉÏ´«½Ó¿Ú£º

<script type="text/javascript">
    var um = UM.getEditor('myEditor', {
        imageUrl: '/upload/image',  //ͼƬÉÏ´«½Ó¿Ú
        imageFieldName: 'upfile',   //ͼƬÌá½»µÄ±íµ¥Ãû³Æ
        imageMaxSize: 2048000,      //ͼƬ¾ÞϸÏÞÖÆ£¬µ¥Î»ÊÇ×Ö½Ú
        imageAllowFiles: ['.jpg', '.png', '.gif', '.jpeg'],  //ÔÊÐíÉÏ´«µÄͼƬÀàÐÍ
    });
</script>

µÇ¼ºó¸´ÖÆ

ÉèÖÃUMEditorµÄÎļþÉÏ´«Â·¾¶£º

<script type="text/javascript">
    UMEDITOR_CONFIG.serverUrl = '/public/UMEditor/php/controller.php/?action=';
</script>

µÇ¼ºó¸´ÖÆ

ÔÚcontroller.phpÖÐ  £¬ÐèÒª½«Í¼Æ¬ÉÏ´«µÄÇëÇóת·¢µ½ÎÒÃǸոձàдµÄͼƬÉÏ´«½Ó¿Ú¡£

ÖÁ´Ë  £¬ÎÒÃÇÒѾ­ÀֳɵØÔÚThinkPHP6ÖÐʵÏÖÁËUMEditor¸»Îı¾±à¼­Æ÷µÄͼƬÉÏ´«¹¦Ð§¡£¿ª·¢Õß¿ÉÒÔͨ¹ýÀàËƵÄÒªÁì  £¬ÊµÏÖÆäËü¸»Îı¾±à¼­Æ÷µÄͼƬÉÏ´«¹¦Ð§¡£

ÒÔÉϾÍÊÇÔõÑùÔÚThinkPHP6ÖоÙÐи»Îı¾±à¼­Æ÷ͼƬÉÏ´«²Ù×÷£¿µÄÏêϸÄÚÈÝ  £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí  £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø  £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是搏ÂËÓÍ»úÍø¹Ù·½Ì¬¶È  £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ  £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢  £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢  £¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是搏ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是搏

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå  £¬9:30-18:30  £¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ