Laravel : To rename an uploaded file automatically

后端 未结 7 1348
北海茫月
北海茫月 2020-12-11 04:31

I am allowing users to upload any kind of file on my page, but there might be a clash in names of files. So, I want to rename the file automatically, so that anytime any fil

7条回答
  •  再見小時候
    2020-12-11 04:46

    at the top after namespace use Storage;

        Just do something like this ....
    

    // read files $excel = $request->file('file');

    // rename file
    $excelName = time().$excel->getClientOriginalName();
    
    // rename to anything
    $excelName = substr($excelName, strpos($excelName, '.c'));
    $excelName = 'Catss_NSE_'.date("M_D_Y_h:i_a_").$excelName;
    $excel->move(public_path('equities'),$excelName);
    

    This guy collect the extension only:

     $excelName = substr($excelName, strpos($excelName, '.c'));
    

    This guy rename its: $excelName = 'Catss_NSE_'.date("M_D_Y_h:i_a_").$excelName;

提交回复
热议问题