laravel上传

https://www.cnblogs.com/blog-dyn/p/10310393.html

1、获取上传的文件

$file=$request->file('file');
2、获取上传文件的文件名(带后缀,如abc.png)

$filename=$file->getClientOriginalName();
3、获取上传文件的后缀(如abc.png,获取到的为png)

$fileextension=$file->getClientOriginalExtension();
4、获取上传文件的大小

$filesize=$file->getClientSize();
5、获取缓存在tmp目录下的文件名(带后缀,如php8933.tmp)

$filaname=$file->getFilename();
6、获取上传的文件缓存在tmp文件夹下的绝对路径

$realpath=$file->getRealPath();
7、将缓存在tmp目录下的文件移到某个位置,返回的是这个文件移动过后的路径

$path=$file->move(path,newname);
move()方法有两个参数,第一个参数是文件移到哪个文件夹下的路径,第二个参数是将上传的文件重新命名的文件名

8、检测上传的文件是否合法,返回值为true或false

$file->isValid()

https://www.jianshu.com/p/bb9b9c4df59c

https://blog.csdn.net/qq_29548433/article/details/74132528

https://blog.csdn.net/qq_16142851/article/details/78296519

https://blog.csdn.net/wangxinxinsj/article/details/68485722

<?php

namespace Modules\Test\Http\Controllers;
use App\Models\Test\Configs;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
//use Illuminate\Support\Facades\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;

$minetype = [
    'image/png'=>'png',
    'image/jpeg'=>'jpg',
    'image/jpg'=>'jpg',
    'image/gif'=>'gif',
    'application/octet-stream'=>'rar',
    'application/x-zip-compressed'=>'zip',
    'application/x-rar'=>'rar',
    'application/zip'=>'zip',
];

$fi = new finfo(FILEINFO_MIME_TYPE);  
$ext = $minetype[$fi->file($_FILES["userfile"]["tmp_name"][$k])]; 
$size = $_FILES["userfile"]["size"][$k];
if($ext!=""&&$_FILES["userfile"]["size"][$k]<5000000){

    //上传

public function upload(Request $request){
       $path = $request->file('img')->store('public');
       echo "<script>top.document.getElementById('img1').src='".$path."';</script>";
       //echo "<script>top.document.getElementById('img1').src='/YsXiQ7xZkYzZ3ZmvDlv01Lo3NBhOj5ifHDrtbLBK.png';</script>";
}

?>

config/filesystem.php

'siyu_tmp' => [
            'driver' => 'sftp',
            'host' => '172.18.21.172',
            'username' => 'yansiyu',
            'password' => '123456',

            // 基于认证的 SSH key 设置...
            // 'privateKey' => '/path/to/privateKey',
            // 'password' => 'encryption-password',

            // 可选的 SFTP 设置...
            // 'port' => 22,
            'root' => '/tmp',
            // 'timeout' => 30,
],

    A+
发布日期:2018年05月29日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: