簡體   English   中英

托管 Laravel 不存儲圖像

[英]hosted Laravel not storing images

我有一個托管在 CPanel 中的 Laravel 項目並且它正在運行,但是當我上傳圖像時,它應該存儲在公共文件夾中,如(“public_path()/posts/theactualimage.jpeg”)。
圖像路徑存儲在數據庫中,但實際圖像實際上根本沒有存儲

在我的本地機器上,事情進展順利,但在主機上卻沒有

我不知道我是否應該做任何配置......

這是文件夾的結構

./
|    public_html
|    |    posts
|    |    index.php 
|    |    some other files
|
|    myapp
|    |    all the other files controllers views ...

這是存儲圖像的 function

public function uploadImage($location, $imageName){
    $name = $imageName->getClientOriginalName();
    $imageName->move(public_path().'/'.$location, date('ymdgis').$name);
    return date('ymdgis').$name;
}

我沒有使用鏈接存儲
謝謝您的幫助

您的 function 缺少處理請求的關鍵要求。 您在 function 上傳圖片中沒有收到任何請求。 您需要在 function 中收到請求,以便您可以進一步處理該請求。 這是一個示例代碼,供您更好地理解。

   /**
     * Storing an Image in public folder.
     *
     * @return \Illuminate\Http\Response
     */
    public function uploadImage(Request $request, $location, $imageName)
    {
        $request->validate([
            'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
        ]);
    
        $imageName = time().'.'.$request->image->extension();  
     
        $request->image->move(public_path('images'), $imageName);
  
        /* Store $imageName name in DATABASE from HERE if you want.  */
    
        return back()
            ->with('success','You have successfully upload image.')
            ->with('image',$imageName); 
    }
}

將圖像存儲在存儲文件夾中

$request->image->storeAs('images', $imageName); // 存儲/app/images/file.png

將圖像存儲在公共文件夾中

$request->image->move(public_path('images'), $imageName); // public/images/file.png

在 S3 中存儲圖像

$request->image->storeAs('images', $imageName, 's3');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM