【问题标题】:403 forbidden dont have permission403 禁止 没有权限
【发布时间】:2021-05-31 08:38:24
【问题描述】:

我正在使用 laravel 网络应用程序将图像上传到数据表并在单击时下载该图像它工作正常((但我希望在单击时下载上传的图像),直到我将代码从 return '{!! Html::link('images/u4.png', 'Download') !!}'; 更改为 @987654323 @ 我得到了这个错误forbidden dont have permission 我正在使用 xampp 本地主机 我的代码让您了解我卡在哪里 index.blade.php

 columns: [
            // render:function(data,type,full,meta){
            //     return '<a href="'+data.filepath+'/'+data.fileName + '" download>Download</a>' 
            // },
            // "targets": 0
          // { data: 'rownum', orderable: false, searchable: false },
            { data: 'doc_type', name: 'doc_type' },                                              
            { data: 'doc_number', name: 'doc_number' },
            { data: 'doc_date', name: 'doc_date'},                                              
            { data: 'amount', name: 'amount' },  
                                                        
            { data: 'currency', name: 'currency' },                                              
            { data: 'partener', name: '{{ TBL_PARTENER }}.id'}, 
            { data: 'image', name: 'image',render:function(data,type,full,meta){
                // return '<a href="'+data.filepath+'/'+data.fileName + '" download="myImage">Download</a>' 
                // return '<a href="/images/.$doc->image" download >Download</a>' 
                 return '{!! Html::link('images/.$doc->image', 'Download') !!}';
                 //  return '{!! Html::link('images/u4.png', 'Download') !!}';
             } }, 
            
            //'image' => ['name' => 'image', 'data' => 'image'],                                   
            { data: 'comments', name: 'comments' },            
            { data: 'action', orderable: false, searchable: false}        
        ],

文档控制器

 public function download($file){
    $file_path = public_path('images/'.$file);
    return response()->download( $file_path);
}

//这段代码写在store方法中

$this->validate($request, [

    'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:6048',
]);
$doc = new Document($request->input()) ;

if($file = $request->hasFile('image')) {
   
   $file = $request->file('image') ;
   
   $fileName = $file->getClientOriginalName() ;
   $destinationPath = public_path().'/images/' ;
   $file->move($destinationPath,$fileName);
   $doc->image = $fileName ;

}

路线

Route::get('/images/{file}','DocumentsController@download');

【问题讨论】:

    标签: javascript php ajax laravel xampp


    【解决方案1】:

    你生成了一个错误的路线兄弟。在屏幕截图中,您攻击浏览器上的 URL 是 localhost/conta/public/images/$doc-&gt;image,这不是有效路由,这就是 apache 抛出“禁止错误”的原因。

    生成有效的网址可能会解决您的问题。

    【讨论】:

    • s 如何写出正确的路线请帮忙,因为我对此很陌生
    • 我删除了 $doc->image 然后它导航到 images 文件夹并显示图像列表
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-19
    • 1970-01-01
    • 2021-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多