【问题标题】:Laravel: store file in sub-directory of strorage pathLaravel:将文件存储在存储路径的子目录中
【发布时间】:2019-07-31 10:41:28
【问题描述】:

我有以下文件夹结构:

-storage 
  -app
    -orders
      -cat1
      -cat2

在cat1 或cat2 文件夹中(取决于用户输入)我想创建另一个文件夹并在其中放置一个xml文件。
这就是我尝试在cat1-文件夹中创建目录并将xml文件放入其中的方式:

$uuid = Uuid::uuid4();
$id = $uuid->toString();
$path = '/orders/cat1/'.$id;
Storage::makeDirectory($path, 0755, true, true);
Storage::put($id.'test.xml', $xml);

会发生什么:
文件夹($id 作为名称)在正确的位置创建:

-storage
  -app
    -orders
      -cat1
        -123456789
      -cat2

但是这里的xml会被存放在另一个文件夹中:

-storage
  -app 
    -123456789   // xml gets stored in another
       -test.xml // folder within app-folder
    -orders
       -cat1
          -123456789 // where the xml should be placed
       -cat2

我似乎可以找到一种方法将 xml 放入我刚刚创建的目录中。_。

【问题讨论】:

    标签: php laravel file storage directory-structure


    【解决方案1】:

    Storage::put 从app 文件夹开始。

    使用此代码:

    Storage::put($path . '/test.xml', $xml);
    

    【讨论】:

    • of Storage::disk('disk')->put($path . '/test.xml', $xml);如果你想/定义另一个磁盘
    【解决方案2】:

    您可以尝试这样存储它:

    Storage::put($path . '/test.xml', $xml);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-24
      • 2020-01-01
      • 2021-10-20
      • 1970-01-01
      相关资源
      最近更新 更多