Laravel 5.5 fopen failed to open stream: Permission denied on Windows 10 using XAMPP

by Mohamed Abdul-Fatah   Last Updated January 14, 2018 12:26 PM

I am using Larave 5.5 on Windows 10 with XAMPP v3.2.2

I am creating a project that stores images when creating a category, it works fine with the dashboard running in the browser, but I am building an API for it and it throws an error via postman

"fopen(C:\xampp\htdocs\tejjarah-laravel-backend\public): failed to open stream: Permission denied"

Here is my code for storing the photos

/**
 * Upload a photo and create a thumbnail.
 * 
 * @param  file  $file
 * @param  string  $path
 * @param  int  $width
 * @param  int  $height
 * @param  boolean  $cover
 * @param  string  $caption
 * @param  string  $method
 * @return void
 */
public function uploadPhoto($file, $path = 'images', $width = 200, $height = 200, $cover = 0, $caption = 'Photo', $method = 'profilePhoto')
{
    $name = microtime(true) * 10000 . '-' . $file->getClientOriginalName();
    $file->storeAs($path, $name, 'files');

    $thumb = Image::make($file)
        ->fit($width, $height);
    $thumb->save(public_path("{$path}/thumb-{$name}"));

    $this->$method()->create([
        'url'       => url("{$path}/{$name}"),
        'thumb'     => url("{$path}/thumb-{$name}"),
        'path'      => "{$path}",
        'caption'   => $caption,
        'cover'     => $cover,
        'file_name' => $name
    ]);
}

The error only appears with the postman, any help will be appreciated.

Tags : php


Related Questions