File upload changes my file name

I can’t get the files original name, I only get the temporary name. Is that normal?

Hey, @elfeffe
here is what you do to find your file original name,

...
public $image;

public function upload()
{
   $fileNameWithExtension = $this->image->getClientOriginalName();

   $fileNameWithoutExtension = str_replace('.', ' ', $fileNameWithExtension);

  $originalName = explode(' ',  $fileNameWithoutExtension)[0];

  $imageName = json_encode([
       'original'  => $originalName,
       'stored'    => $this->generateHashNameWithOriginalNameEmbedded($this->image)
     ]);
} 

    private function generateHashNameWithOriginalNameEmbedded($file)
    {
        $hash = Str::random(30);
        $meta = '-meta' . base64_encode($file->getClientOriginalName()) . '-';
        $extension = '.' . $file->guessExtension();

        return $hash . $meta . $extension;
    }

this is my way on how I handle the file uploads in LW, I hope you find something useful in it.

1 Like

Thank you!
I have found that Laravel changes the file name after upload.
Thank you for your help.

You are very welcome mate.