如何将laravel中的完整XML文件从公共文件夹复制到存储文件夹

问题描述 投票:0回答:1

在我的Laravel项目中,我想将一个名为config.xml的.xml文件从public / xml文件夹复制到storage / Admin / webapp文件夹。(存储是符号链接的)似乎我无法让它工作。 我总是得到一个“无法创建根目录”的例外。

如果我知道变量我得到了我想看到的结果。 我尝试了几种方法来通过改变/到\\或删除和添加一些/或使用laravel如资产等的几个命令来实现它。似乎我可以获得.xml文件甚至显示其内容与dd但我得到例外之后复制它? 有一个双根。 两次C:\\但我不知道它来自哪里。

我希望从我的存储文件夹中的公共文件夹中将config.xml文件的副本作为config.xml文件

public function copyXml()
  {
    //Create Filepath and get XML File
    $content = file_get_contents(public_path('/xml/config.xml'));

    //Set destination path
    $destination = storage_path('/Admin/webapp');

    //Copy xml-file
    Storage::put($content, $destination);
 }
xml laravel controller file-copying
1个回答
0
投票

在此输入图像描述

默认情况下,本地磁盘会查看project_root_folder / storage / app /。 您无法通过Storage Facac访问和操作公用文件夹中的文件。

//Get file content from public path
$content = file_get_contents(public_path('xml/config.xml'));

//Set destination path
$destination = storage_path('admin/webapp/config.xml');

//Put content in the destination path
Storage::put($destination, $content);
© www.soinside.com 2019 - 2024. All rights reserved.