Debug School

rakesh kumar
rakesh kumar

Posted on

How to check public path to store image in laravel

In Laravel, the public path is typically accessible through the public_path() helper function. You can use this function within your controller to determine the public path for storing images. Here's an example of how you can check the public path in a Laravel controller:


namespace App\Http\Controllers;

use Illuminate\Http\Request;

class YourController extends Controller
    public function storeImage(Request $request)
        // Get the public path
        $publicPath = public_path();

        // Alternatively, you can specify a subdirectory within the public path
        // $publicPath = public_path('images');

        // You can then use the public path to construct the full image path
        $imagePath = $publicPath . '/your-image-folder/' . $request->file('image')->getClientOriginalName();

        // Store the image
        $request->file('image')->move($publicPath . '/your-image-folder/', $request->file('image')->getClientOriginalName());

        // You can also store the image path in a database or perform other actions with it

        // ...
Enter fullscreen mode Exit fullscreen mode



                    log::info("hasfile path hai");             
                    $file= $request->file('image_logo');   
                    $name = $file->getClientOriginalName();
                    $publicPath = public_path();
                    log::info("public path hai");
                    $file->move(public_path().'/storage/item/', $name);  
Enter fullscreen mode Exit fullscreen mode

In the example above, the public_path() function returns the absolute path to the Laravel application's public directory. You can concatenate this path with the desired subdirectory or folder where you want to store the image. Then, you can use the move() method to move the uploaded image to the specified location.

Remember to adjust the your-image-folder part in the code to match the actual folder name where you want to store the image.

Top comments (0)