dimanche 29 novembre 2015

Laravel 5.1 file upload, File's same name for folder and database

My controller code where i store the file name into a database table and also moving the file to a folder.

The issue is that i am storing the original name of a file in database table, in contrast i am moving files with uniqueid() and time() . It will arise issues in future. because in database table file name and moved file are with different names.

if(Input::hasFile('profile_pic')){
            $pic = Input::file('profile_pic');
            $mobile->photo1 = $pic[0]->getClientOriginalName();
            $mobile->photo2 = $pic[1]->getClientOriginalName();
            $mobile->photo3 = $pic[2]->getClientOriginalName();
            $mobile->photo4 = $pic[3]->getClientOriginalName();
            $mobile->photo5 = $pic[4]->getClientOriginalName();
                foreach ($pic as $k=>$file){
                    if(!empty($file)){
                        $file->move(public_path() . '/uploads/', time() . uniqid() . '-' . $k . '-laptop');
                    }
                }
        }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire