【问题标题】:How to Copy a complete XML-file in laravel from public to storage folder如何将 laravel 中的完整 XML 文件从公共文件夹复制到存储文件夹
【发布时间】:2019-10-13 23:52:40
【问题描述】:

在我的 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】:

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

    //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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-21
      • 2016-06-06
      • 2016-07-02
      • 2011-11-15
      • 2015-01-03
      • 2021-09-08
      • 2021-11-02
      • 1970-01-01
      相关资源
      最近更新 更多