Php 拉雷维尔5元';t从存储部分删除文件
当我试图通过控制器删除特定文件时,我得到一个错误 很抱歉,找不到您要查找的页面。 NotFoundHttpException 这是我的控制器:Php 拉雷维尔5元';t从存储部分删除文件,php,laravel,laravel-5,laravel-5.2,Php,Laravel,Laravel 5,Laravel 5.2,当我试图通过控制器删除特定文件时,我得到一个错误 很抱歉,找不到您要查找的页面。 NotFoundHttpException 这是我的控制器: public function destroyFile($file_name) { $file = storage_path('documents').'/'.$file_name; Storage::delete($file); return redirect('/documents'); } 我的路线: Route::d
public function destroyFile($file_name)
{
$file = storage_path('documents').'/'.$file_name;
Storage::delete($file);
return redirect('/documents');
}
我的路线:
Route::delete('documents/{file}','FilesController@destroyFile');
我的看法是:
{!! Form::open(['method' => 'DELETE', 'action' => ['FilesController@destroyFile', $file->name] ]) !!}
{!! Form::hidden('_method', 'DELETE') !!}
{!! Form::token() !!}
{!! Form::submit(trans('buttons.del-cat'),['class'=>'btn btn-danger user-delete push-right']) !!}
{!! Form::close() !!}
我也有同样的问题,一切都安排好了,但还是不起作用 我用了
File::delete()
而不是Storage::delete()
,这就解决了它
希望这能奏效 我也遇到了同样的问题,一切都安排好了,但仍然不起作用
public function images(Request $request,$id){
$user_id=$request->session()->get('user_id');
$data=DB::table('company_images')->where('id',$id)->first();
//deleteing the image from database and server
DB::table('company_images')->where('id', '=', $id)->delete();
//delete the image form the server
$path=public_path("/assets/img/company/$data->image");
unlink($path);
return redirect("/company/$user_id/add_details")->with('delete','delete');
}
我用了File::delete()
而不是Storage::delete()
,这就解决了它
希望这能奏效
public function images(Request $request,$id){
$user_id=$request->session()->get('user_id');
$data=DB::table('company_images')->where('id',$id)->first();
//deleteing the image from database and server
DB::table('company_images')->where('id', '=', $id)->delete();
//delete the image form the server
$path=public_path("/assets/img/company/$data->image");
unlink($path);
return redirect("/company/$user_id/add_details")->with('delete','delete');
}
这是我用来使用unlink($path)删除公司图片的功能。这对我来说很好。还有一个重要的提示:你应该仔细写下你删除的文件的路径
这是我用来使用unlink($path)删除公司图片的功能。这对我来说很好。还有一个重要的提示:你应该仔细写下你删除的文件的路径 必须在
filesystem.php
中设置public
:
'default'=>env('FILESYSTEM\u DRIVER','public')
而不是:
'default'=>env('FILESYSTEM\u DRIVER','local')
将
local
更改为public
您必须在filesystem.php中设置public
:
'default'=>env('FILESYSTEM\u DRIVER','public')
而不是:
'default'=>env('FILESYSTEM\u DRIVER','local')
将local
更改为public
哪个请求失败…删除到/documents/{file}或重定向到/documents?重定向失败,但仍然没有删除存储中的文件在调用Storage::DELETE($file)
时,$file的计算结果是什么?该文件是否确实存在于指定的路径上?exist($file)表示fals,但该路径中有一个类似的文件听起来好像没有文件…请仔细检查配置、路径和扩展名以及所有内容。哪个请求失败…删除/documents/{file}或者重定向到/documents?重定向失败,但仍无法删除存储中的文件在调用Storage::delete($file)
时,$file的计算结果是什么?该文件是否确实存在于指定的路径上?exist($file)表示fals,但该路径中有一个类似的文件。听起来那里没有文件……请仔细检查配置、路径和扩展名以及所有内容。