简体   繁体   中英

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在此处输入图片说明

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在此处输入图片说明

How can i fix this error

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';
});

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM