Laravel:将文件存储在存储路径的子目录中

我有以下文件夹结构:


-storage 

  -app

    -orders

      -cat1

      -cat2

在cat1或cat2文件夹中(取决于用户输入),我想创建另一个文件夹并在其中放置一个 xml 文件。

这就是我尝试在cat1-folder 中创建目录并将 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 放在我刚刚创建的目录中。 _。


UYOU
浏览 198回答 2
2回答

胡说叔叔

Storage::put从app文件夹开始。使用此代码:Storage::put($path . '/test.xml', $xml);

Cats萌萌

您可以尝试像这样存储它:Storage::put($path . '/test.xml', $xml);
打开App,查看更多内容
随时随地看视频慕课网APP