dtrhd2850 2018-07-12 09:27 采纳率: 0%
浏览 528
已采纳

Laravel Filesystem - 将文件从一个磁盘移动到另一个磁盘

I am trying to move files from my FTP server to a local directory. First I need to find the correct file from the FTP server, as there can be a few hundreds:

//Search for the file.
$fileName= array_filter(Storage::disk('ftp')->files(), function ($file)
{
   return preg_match('/('.date("Y-m-d" ,time()).').*.XLSX/', $file);
});

Above finds the correct file. If I dd($fileName), I get this: My File Name.XLSX

I then try to move that file, to my public disk:

 $ftp_file = Storage::disk('ftp')->get($fileName);
 $local_file = Storage::disk('public')->move($ftp_file, "moved_file.xlsx");

However above code doesn't work. I get below error:

preg_match() expects parameter 2 to be string, array given

Which I have identified being on below function:

$ftp_file = Storage::disk('ftp')->get($fileName);

What am I doing wrong? How can I move the file, which I am able to find on my FTP server, to my local disk?

Thank you in advance.

  • 写回答

1条回答 默认 最新

  • doz95923 2018-07-16 07:34
    关注

    As @Loek pointed out, $fileName was an array, and therefore to access it I needed to use:

     $ftp_file = Storage::disk('ftp')->get($fileName[0]);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!