【问题标题】:Function rename() remove catalog with files函数 rename() 删除包含文件的目录
【发布时间】:2018-06-18 22:32:21
【问题描述】:

我尝试将文件从目录'storage/cvs/' 移动到'storage/r_cvs/'。我有代码:

$getOldCV = $worker->cv;
$createCatalogNameCV = $request->name."_".$request->surname;
$createCatalogCV = iconv('UTF-8', 'ISO-8859-1//TRANSLIT//IGNORE', $createCatalogNameCV);
// Storage::move('storage/cvs/'.$getOldCV, 'storage/r_cvs/' . $createCatalogCV . '/' . $getOldCV);
rename('storage/cvs/'.$getOldCV, 'storage/r_cvs/' . $createCatalogCV . '/' . $getOldCV);

当我移动文件$getOldCV 时,文件被移动,但是脚本删除了所有目录'storage/cvs/' 和文件。我尝试使用rename()和Laravel函数Storage::move,但效果是一样的。

【问题讨论】:

    标签: php laravel move


    【解决方案1】:

    由于您使用的是 Laravel,您可以使用 Storage::move() 方法:

    Storage::move(storage_path('csv/' . $getOldCV), storage_path('r_cvs/' . $createCatalogCV . '/' . $getOldCV));
    

    File::move()。不同于Storage::move()

    File::move(storage_path('csv/' . $getOldCV), storage_path('r_cvs/' . $createCatalogCV . '/' . $getOldCV));
    

    另外,请确保storage 目录的文件权限正确。

    【讨论】:

      【解决方案2】:

      我将rename() 更改为move_uploaded_file(),现在脚本工作正常

      【讨论】:

        【解决方案3】:

        你可以做一个 copy() 和 unklink() 代替:

        copy('storage/cvs/'.$getOldCV, 'storage/r_cvs/' . $createCatalogCV . '/' . $getOldCV);
        unlink('storage/cvs/'.$getOldCV);
        

        【讨论】:

          猜你喜欢
          • 2011-03-21
          • 1970-01-01
          • 2023-03-05
          • 1970-01-01
          • 2012-06-14
          • 1970-01-01
          • 2023-01-04
          • 1970-01-01
          • 2014-01-14
          相关资源
          最近更新 更多