laravelデータベースの画像の名前を変更する

これで、データベースにアップロードされたすべてのファイルの名前を変更する必要があるという要件があります。次の方法を使用すると、すばやく処理できます

ini_set( "max_execution_time"、0); 
/ *チャンク分処理データ* / 
       DB :: table( 'xxx')-> orderby( 'id')-> where( 'imageurl'、 '<>'、 '')-> chunk(100、function ($ rows)
        { 
           // $ list = []; 
            foreach($ rows as $ row)
            { 
                $ fileInfo = pathinfo($ row-> imageurl); 
                $ newFileName = '。'。$ fileInfo ['dirname']。 ' /'.$fileInfo['filename'].time().'.'.$fileInfo['extension ']; 
                echo'正在处理: '。$ newFileName。' id: '。$ row-> id。' < br /> '; 

                if(file_exists('。 '。$ row-> 
                imageurl)) { 
                  rename( '。'。$ row-> imageurl、$ newFileName); 
                }
                echo var_dump(['id' => $ row-> id、 'imageurl' => substr($ newFileName、1)]);
                $ content = ob_get_contents(); 
                スリープ(1); 
                DB :: table( 'km')-> where( 'id'、$ row-> id)-> update(['imageurl' => substr($ newFileName、1)]); 

            } 
          

        });

  

おすすめ

転載: www.cnblogs.com/fogwang/p/12704205.html
おすすめ