Xron's avatar
Level 1

Issue using ->move()

I'm trying to move a file once it's uploaded but I'm having an issue, I've tried a number of things but for some reason when a file is uploaded it throws a 500 error with "page isn't working".

This is what I have inside my control so far;

   protected $allowedFileExt = [
        'png',
        'jpg',
        'gif',
    ];

    public function postImage (Request $request) 
    {
        $file = $request->file('image');
        
        if(!$file) {
            return redirect()->back();
        }

        if(!$this->isAllowedFile($file)) {
            return redirect()->back();
        }

        $name = str_random(255) . '.' . $file->getClientOriginalExtension();

        $destinationPath = 'showcase';

        $upload_success = $file->move($destinationPath, $name);

        return redirect()->back();
    }

    protected function isAllowedFile(UploadedFile $file)
    {
        return in_array(
            $file->getClientOriginalExtension(),
            $this->allowedFileExt
        );
    }
0 likes
0 replies

Please or to participate in this conversation.