关于删除laravel 5中的文件的问题


Issue on delete a file in laravel 5

我正在尝试删除laravel 5应用程序中的一个文件。我的控制器代码是

public function deleteImages(){
        $image = public_path() . '/uploads/images/'.Input::get('image');
        Storage::Delete($image);
    }

我收到一条类似的错误消息

local.ERROR: exception 'League'Flysystem'FileNotFoundException' with message 'File not found at path: var/www/html/wonders/uploads/images/Copy1Copy1Kuruva-Islands.jpg' in /var/www/html/wonders/vendor/league/flysystem/src/Filesystem.php:381

但是该文件确实存在,并且路径是正确的。但我想知道为什么它显示了这样一个错误。

在我发现的文档中:

使用本地驱动程序时,请注意,所有文件操作都与配置文件中定义的root目录相关。默认情况下,此值设置为存储/app目录。因此,以下方法将文件存储在storage/app/file.txt中:

Storage::disk('local')->put('file.txt', 'Contents');

在我看来,您不能在此处使用Storage::delete,因为您正试图删除公用文件夹中的文件。

试试我在Laravel Recipies上发现的其中一个:

// Delete a single file
'File::delete($filename);
// Delete multiple files
'File::delete($file1, $file2, $file3);
// Delete an array of files
$files = array($file1, $file2);
'File::delete($files);

我添加了一个前导'',因为您使用的是Laravel 5。

尝试使用文件::删除($filename);

或者参考这些链接http://laravel-recipes.com/recipes/133/deleting-a-file

https://laracasts.com/discuss/channels/general-discussion/l5-how-to-delete-a-file-using-filesystem

假设您的代码是正确的:您是否检查了要删除的文件的所有权和权限?也许您的web服务器用户没有适当的权限来操作所述文件。

我不确定你在哪个平台上工作,但在debian/apache2环境中,文件所有者通常应该是www数据,权限应该是644。