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 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题