K M Rifat ul alom
K M Rifat ul alom

Reputation: 525

Can't write image data to path laravel 5.2

I host my laravel application in a seared hosting and i upload my laravel project into the root directory and i upload my public folder into the public_html directory .

Image enter image description here

i want to save image in avater_img or assistant_img or doctor_img.

For thereby i write this code

$file = Input::file('photo');
        if($file != ""){
            $ext = $file->getClientOriginalName();
            $file_name = rand(10000,50000).'.'. $ext;
            $image = Image::make(Input::file('photo'));
            $image->resize(300,300);
            $image->save(public_path() . '/doctor_img/' . $file_name);
        }

And it give this error back enter image description here

How can i fix this error

Upvotes: 1

Views: 903

Answers (3)

Sushil More
Sushil More

Reputation: 59

Your image path is wrong. It should be like this.

$image->save(public_path() . '../doctor_img/' . $file_name);

As public_path() goes to public folder.

Upvotes: 0

Alief
Alief

Reputation: 459

The problem is you are not using the default Laravel file structure, therefore your public_path() is still pointed into /home/dermopres/laravel/public as mentioned in the error message.

First thing that you should do is set your Laravel application according to your current file structure.

On your public_html/index.php change the following line:

require __DIR__.'/../bootstrap/autoload.php';

$app = require_once __DIR__.'/../bootstrap/app.php';

to

require __DIR__.'/../laravel/bootstrap/autoload.php';

$app = require_once __DIR__.'/../laravel/bootstrap/app.php';

and also add this line to the /laravel/bootstrap/app.php:

$app->bind('path.public', function() {
return __DIR__.'/../../public_html';
});

Upvotes: 1

Shyam Achuthan
Shyam Achuthan

Reputation: 950

you have to make the doctor_img directory writable

if you are on linux / homestead

run below on terminal

sudo chmod 666 -R /home/dermopres/laravel/public/doctor_img

Upvotes: 0

Related Questions