lundi 11 mars 2019

PHP image upload doesn't save in directory

In my script I have the following code for profile images but after users upload the picture is not uploaded in any folders and they look like this : /182321883jpg and the extension doesn't have a dot . is there anything wrong with this code?

            $img = $request->file('profile_img');
        if ($img) {
            $random_number = rand(100000000,999999999);
            $valid_extensions = ['jpeg', 'jpg', 'png'];
            $imgExt = $img->getClientOriginalExtension();
            $imgName = $random_number.$imgExt;
            $imgDir = public_path('uploads/users/profilepics/');
            if (in_array($imgExt, $valid_extensions)) {
                if (File::exists($imgDir)) {
                    File::deleteDirectory($imgDir);
                }
                File::makeDirectory($imgDir, 0777, true, true);
                $request->profile_img->move($imgDir, $imgName);
                $info_data->user_image = $imgName;
            }
        }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire