第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

在帶有 Laravel 的目錄中查找最小文件大小?

我需要從目錄中找到最小的文件大小。使用 Laravel并盡可能減少代碼的最佳方法是什么?我正在使用這段代碼,但我相信有一種更好、更有效的方法。$files = Storage::files("videos");$files = Arr::where($files, function ($value, $key) {    return Str::contains($value, 'string..') && Str::endsWith($value ,'.mp4');}); // keep only certain files from videos directory in the files arrayforeach ($files as $key => $file){    $files[$key] = ['file' => $file, 'size' => Storage::size($file)]; }$min = collect($files)->min('size'); // 1000000// find file by size...
查看完整描述

2 回答

?
PIPIONE

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超9個(gè)贊

我認(rèn)為您可以使用回調(diào)根據(jù)文件大小對文件進(jìn)行排序。也許是這樣的東西,sortBy


//after Arr::where

$fileWithSmallestSize = collect($files)->sortBy(function($file){

    return Storage::size($file);

})->first();

另一種選擇是減少收集。


//after Arr::where

$fileWithSmallestSize = collect($files)->reduce(function($smallestFile, $file){

    return ( Storage::size($file) < Storage::size($smallestFile) )? $file : $smallestFile;

}, $files[0]);


查看完整回答
反對 回復(fù) 2023-10-22
?
慕容森

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超18個(gè)贊

循環(huán)文件時(shí)保持最小:


$files = Storage::files("videos");


$files = Arr::where($files, function ($value, $key) {

    return Str::contains($value, 'string..') && Str::endsWith($value ,'.mp4');

}); // keep only certain files from videos directory in the files array


$minSize = PHP_INT_MAX;

$minFile = null;

foreach ($files as $key => $file)

{

    $size = Storage::size($file);

    if ($size < $minSize) {

      $minSize = $size;

      $minFile = $file;

    }

    $files[$key] = ['file' => $file, 'size' => $size]; 

    

}


// $minSize is the smallest size in the directory and $minFile is the file with the smallest size


// $minFile will be `null` if there are no files in the initial array, you should add a check for this possibility



查看完整回答
反對 回復(fù) 2023-10-22
  • 2 回答
  • 0 關(guān)注
  • 177 瀏覽

添加回答

了解更多

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號