Laravel not uploading actual files on server

342 views Asked by At

I recently hosted my first Laravel project. This therefore means that the public folder is on public_html while the others are on one forder in the root.

I was uploading a file to the server and got the error Could not create img/photos directory (paraphrase). I googled for quite some time and after that i gave 777 permission to img and photos and the error disappeared. The only thing is that now there is no error being caught but the file is just not being uploaded.

NOTE: In my form declaration i have set 'files'=>true, i have properly modified my autoload and paths.php paths.

// controller
            // upload cover photo if any
            $path = public_path().'/img/album-cover-photos';
            if(Input::hasFile('photo'))
            {
                $ext = Input::file('photo')->getClientOriginalExtension();
                $name = "Album-Cover-".$album->id.'-'.date('YmdHis').'.'.$ext;

                Input::file('photo')->move($path,$name);
                $album->cover_photo = $name;
                $album->save();
            }

What could the issue be?

2

There are 2 answers

0
gthuo On BEST ANSWER

Let me answer this. I got where the problem was. Even if i insisted in the question that I had set paths.php paths correctly, that was exactly where the problem was. public path had been set as __DIR__.'/../public_html/mylaravelpublic instead of __DIR__.'/../../public_html/mylaravelpublic. I really hope that this helps somebody.

Just to say, im on shared hosting so my laravel public folder contents are put in a public_html subfolder as above, and not in public_html itself.If you are not on shared hosting, i think your path should just end at public_html without any subfolder.

0
Sid Heart On
$path = public_path().'/../img/album-cover-photos';
            if(Input::hasFile('photo'))
            {
                $ext = Input::file('photo')->getClientOriginalExtension();
                $name = "Album-Cover-".$album->id.'-'.date('YmdHis').'.'.$ext;

                Input::file('photo')->move($path,$name);
                $album->cover_photo = $name;
                $album->save();
            }`enter code here`