eokorie's avatar

L5.2 File upload issues

I hope someone here can help me clear up a small issue I have with my Laravel application.

I currently have a page that allows me to upload files using Dropzone. I am using plank/laravel-mediable to upload files and assign them to their different models and spatie/laravel-glide to generate thumbnails. All works very well on my local dev environment (XAMPP windows). However on my ubuntu production server, while I am able to upload the files, I am not able to generate thumbnails.

I am getting the following error:

League\Flysystem\ExceptionPOST /admin/portfolio/edit/24
Impossible to create the root directory "/tmp/phpCdW7I9"

The code itself is as follows:

public function store(CreatePortolioProjectRequest $request)
    {

        //dd($request->all());

        $project = Portfolio::create($request->all());
       
        if ($request->hasFile('file')) {
                $file = $request->file('file');
                $string = str_random(32);
                $filename = $string;
                $thumbFilename = $filename . '.' . strtolower($file->getClientOriginalExtension());

                $media = MediaUploader::fromSource($file)
                    ->setFilename($filename)
                    ->setDirectory('portfolio')
                    ->upload();

                $project->attachMedia($media, $project->category->alias_cprj);

                // Generate thumbnails for uploaded media
                $path = public_path('uploads' . DIRECTORY_SEPARATOR . 'portfolio' . DIRECTORY_SEPARATOR . 'thumbs');

                if (!File::exists($path)) {
                    File::makeDirectory($path);
                }

                GlideImage::create($file) 
                    ->modify([
                        'w'    => 600,
                        'h'    => 300,
                        //'filt' => 'greyscale',
                        'fit'  => 'crop',
                    ])
                    ->save($path . DIRECTORY_SEPARATOR . $thumbFilename); // Code breaks here!!

                $thumb = new Media;
                $thumb->disk = 'uploads';
                $thumb->directory = 'portfolio/thumbs';
                $thumb->filename = $filename;
                $thumb->extension = strtolower($file->getClientOriginalExtension());
                $thumb->mime_type = $file->getClientMimeType();
                $thumb->aggregate_type = Media::TYPE_IMAGE;
                $thumb->size = filesize($path . DIRECTORY_SEPARATOR . $thumbFilename);
                $thumb->save();

                $project->attachMedia($thumb, $project->category->alias_cprj . '-thumb');
  
        }
}

I have attempted to change the file permissions for the /tmp folder to allow the user www-data to write to it. However this is not working. In the /tmp folder, if I do an ls -lah, I get -rw------- 1 www-data www-data 424K Aug 21 09:03 Glide2myyHf

And that's as far as it goes.

Anyone have an idea as to how I can fix this problem?

Not a great linux user but trying to my head round the whole permissions thing :) Thanks

0 likes
3 replies
eokorie's avatar

@tisuchi thanks for the link. However the code I wrote, already works well on a windows environment. I am able to upload my file via dropzone with no issues. The issue I am facing seems to be more of a permissions problem on the /tmp folder in Ubuntu.

tisuchi's avatar

If it is only folder permission issue, who not just change the permission of that?

Please or to participate in this conversation.