marcoB's avatar

Storage::put with SVGs is creating a folder instead of a file

Hello,

I am developing an app where users can upload SVGs.

However, when I do Storage::put($image_path.'2022-03-14.svg', $image);, it is creating 2022-03-14.svg > dzapiYUIHIjkndezzaçBkK.svg (the SVG file in inside a folder). When I try the same with a PNG, there is no issue.

I have no clue of what s happening. Any help would be welcomed :)

Have a great day.

0 likes
5 replies
Sinnbeck's avatar

Can you show the full code for this? Also, what is your filesystem default driver set to?

What is the exact path/name of the file on disk?

marcoB's avatar

@Sinnbeck the full code if a bit everywhere but to sum it up :

//Controller
    public function store(Request $request){
       ...
       GestionLogo::stocker_logo($request->file('logo'), $asso_id);
   }

//Service class
public static function stocker_logo($image, $asso_id, $ext=null){
        $asso = Association::find($asso_id);
        $chemin = self::chemin_logo($asso->uid, $asso_id, $asso->type);
        if(is_null($ext)){$ext = $image->extension();}

        self::stocker_fichier_logo($image, $chemin, $ext);
        $logo = new Logo;
         ...
        $logo->save();
    }
static function stocker_fichier_logo($image, $chemin, $ext){
        $image_nom = date("Y-m-d");
        $image_chemin = $chemin . $image_nom;
        if($ext == "svg"){
            Storage::put($image_chemin .'.svg', $image);
        } else {
            Storage::put($image_chemin .'.png', $image);
       }
        return $image_nom;
    }

When I upload PNGs, there is no issue at all ^^.

The default driver is the local one.

Sinnbeck's avatar

@marcoB Ok lets debug a bit.

static function stocker_fichier_logo($image, $chemin, $ext){
        $image_nom = date("Y-m-d");
        $image_chemin = $chemin . $image_nom;
        if($ext == "svg"){
           dd($image_chemin); //what is the output of this ?
            Storage::put($image_chemin .'.svg', $image);
        } else {
            Storage::put($image_chemin .'.png', $image);
       }
        return $image_nom;
    }

And what was the exact path the svg was saved as?

1 like
marcoB's avatar

@Sinnbeck The image is saved at \storage\app\public\images\associations\bda-16\logos\2022-03-14.svg\75lFP2R74mwBabmm7xaNc6nF2xqxBuFVk2OWE3l0.svg" and $image_chemin (image_path in english) is images/associations/bda-16/logos/2022-03-14

thanks a lot for your time

marcoB's avatar

The strange part is that the tmp file is just a SVG. When I log $request->logo, i get "C:\wamp64\tmp\phpFB1D.tmp"

Beside, when I just write Storage::put() as the first line of store(), it is not working either.

-- EDIT -- When using Storage::putFileAs(), it works.

Please or to participate in this conversation.