thinkphp5上傳圖片及生成縮圖公共方法
直接上程式碼,可以寫在公共檔案common和繼承的基礎類中,方便呼叫
/* * $name為表單上傳的name值 * $filePath為為儲存在入口資料夾public下面uploads/下面的資料夾名稱,沒有的話會自動建立 * $width指定縮略寬度 * $height指定縮略高度 * 自動生成的縮圖儲存在$filePath資料夾下面的thumb資料夾裡,自動建立 * @return array 一個是圖片路徑,一個是縮圖路徑,如下: * array(2) { ["img"] => string(57) "uploads/img/20171211\3d4ca4098a8fb0f90e5f53fd7cd71535.jpg" ["thumb_img"] => string(63) "uploads/img/thumb/20171211/3d4ca4098a8fb0f90e5f53fd7cd71535.jpg" } */ protected function uploadFile($name,$filePath,$width,$height) { $file = request()->file($name); if($file){ $filePaths = ROOT_PATH . 'public' . DS . 'uploads' . DS .$filePath; if(!file_exists($filePaths)){ mkdir($filePaths,0777,true); } $info = $file->move($filePaths); if($info){ $imgpath = 'uploads/'.$filePath.'/'.$info->getSaveName(); $image = \think\Image::open($imgpath); $date_path = 'uploads/'.$filePath.'/thumb/'.date('Ymd'); if(!file_exists($date_path)){ mkdir($date_path,0777,true); } $thumb_path = $date_path.'/'.$info->getFilename(); $image->thumb($width, $height)->save($thumb_path); $data['img'] = $imgpath; $data['thumb_img'] = $thumb_path; return $data; }else{ // 上傳失敗獲取錯誤資訊 return $file->getError(); } } }
相關推薦
thinkphp5上傳圖片及生成縮圖公共方法
直接上程式碼,可以寫在公共檔案common和繼承的基礎類中,方便呼叫 /* * $name為表單上傳的name值 * $filePath為為儲存在入口資料夾public下面uploads/下面的資料夾名稱,沒有的話會自動建立 * $width指
thinkphp上傳圖片及生成縮圖
一、上傳圖片的HTML程式碼 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> &
thinkphp上傳圖片,生成縮圖
Image.php <?php /** * 實現圖片上傳,圖片縮小, 增加水印 * 需要定義以下常量 * define('ERR_INVALID_IMAGE', 1); * define('ERR_NO_GD',
php上傳圖片自動生成縮圖方法函式
$file_name='C:\AppServ\www\_MG_9888.jpg'; $file_new='C:\AppServ\www\bbbb.jpg'; scal_pic($file_name,$file_new); function scal_pic($file_n
上傳圖片並生成縮圖(ASP.NET+VB.NET)
Sub upimages() Dim iname As String If Not (fileup.PostedFile Is Nothing) Then Dim namestr1 As String = (fileu
tp5上傳圖片並生成縮圖
<?php namespace app\common\controller; use app\common\model\Goods; class Tools { public stati
PHP.25-TP框架商城應用實例-後臺1-添加商品功能、鉤子函數、在線編輯器、過濾XSS、上傳圖片並生成縮略圖
引用傳遞 none move 名稱 textarea 如果 library time fields 添加商品功能 1、創建商品控制器【C】 /www.test.com/shop/Admin/Controller/GoodsController.class.php
C# 上傳檔案並生成縮圖
#region 上傳檔案並生成縮圖 /// <summary> /// 上傳檔案並生成縮圖 /// </summary> /// <param name
Larvel5.2上傳圖片並顯示縮圖
1.建立控制器UploadController.php <?php namespace App\Http\Controllers; use App\Http\Requests; use App\Http\Controllers\Controller; use I
改變dede圖片上傳路徑(商品-縮圖)去掉/allimg/ymd/
include\common.inc.phpline185://上傳的普通圖片的路徑,建議按預設//lyy $cfg_image_dir = $cfg_medias_dir.'/allimg';$cfg
asp.net core 通過ajax上傳圖片及wangEditor圖片上傳
images use class multi jquery 開始 load als org asp.net core 通過ajax上傳圖片 .net core前端代碼,因為是通過ajax調用,首先要保證ajax能調用後臺代碼,具體參見上一篇.net core 使用ajax
laravel5.6上傳圖片及顯示
drive ray cover 大神 encode end real md5 over 借鑒大神博客:https://blog.csdn.net/tony_110/article/details/80105099文檔:laravel5.6文檔 文件傳輸 在config下新建
form表單,上傳圖片及展示
pen bdc type comm 之前 jpg ctype turn ali .comment_con .file{position: relative;top:2rem;z-index: 999;width: 5rem;height: 5rem;background:
UEditor 上傳圖片等比例縮放
修改ueditor.all.js 16995行 updateTargetElement: function(){}裡的內容為 updateTargetElement: function () { var me = this; var newWidt
PHP將上傳圖片自動放縮到指定解析度,保持清晰度
class AutoImage{ private $image; public function resize($src, $width, $height){ //$src 就是 $_FILES['upload_image_file']['tmp_name']
js上傳視訊並擷取縮圖
<!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8"> </head> <body> <input
如何利用PHP實現上傳圖片及視訊到七牛雲?
七牛是一家怎樣的公司? 七牛雲(隸屬於上海七牛資訊科技有限公司)是國內領先的以視覺智慧和資料智慧為核心的企業級雲端計算服務商,同時也是國內最有特色的智慧視訊雲服務商,累計為 70 多萬家企業提供服務,覆蓋了國內80%網民。圍繞富媒體場景推出了物件儲存、融合 CDN 加速、容
織夢DEDECMS百度編輯器Ueditor上傳圖片及下載遠端圖片無法加水印的解決方法
一、開啟 \include\ueditor\php\action_upload.php 找到include "Uploader.class.php";在下面新增:require_once("../../common.inc.php"); require_once("../..
js 移動端漂亮input框上傳本地,顯示縮圖,點選可以檢視大圖
//首先根據id得到input框的檔案,判斷大小,如果大於100M就不給上傳,如果不大於就可以上傳 $("input[type='file']").on("change",function(){ var load =$(this).attr("id"); var fileSize
java ssh上傳視訊並顯示縮圖以及視訊在網頁中的播放
非原創,整合網上的各個步驟及自己的實施 一.上傳視訊 使用以下htm標籤即可 <form name="uploadForm" method="post" enctype="multipart/form-data" action="xxx" <td><input