lipa's avatar
Level 1

Getting names of uploaded files

I working on upload system. Uploading files works OK, but I have problem with getting name of uploaded file. I would like to store files on server with the same name as before upload.

I'm using file upload jquery to keep it clean and simple.

My code:

public function upload()
    {

        $file = \Request::file('files');
        $userId = \Request::get('userid');
            
        foreach($file as $currFile) {
        
        $storagePath = storage_path().'/dokumenty/'.$userId.'/';        
        $fileName = $currFile->getClientOrginalName();
        
        //When I set $fileName as some random string (asdasf.png) it works well
        return $currFile->move($storagePath,$fileName); 
        }

    }   

I get error:

Call to undefined method Symfony\Component\HttpFoundation\File\UploadedFile::getClientOrginalName()
0 likes
1 reply
lipa's avatar
lipa
OP
Best Answer
Level 1

Made this work :)

Make my upload working by defining file name directly in return:

        return $currFile->move($storagePath, $currFile->getClientOriginalName());   

Please or to participate in this conversation.