SomeNewbieBoy's avatar

File name is being encrypted when saving it with store() function, but why?

UploadedFile $file->store($path, $name) We have this function in our app:

    public static function upload(UploadedFile $file, $base_folder, $sub_folder = null) 
    {
        $folder = is_null($sub_folder) ? $base_folder : ($base_folder . '/' . $sub_folder);
        $path = $file->store($folder);
        return $path;
    }

When I call it like this

$path = Class::upload('file_uno.pdf', 'folder_name');

I get the result $path == 'folder_name/some_hash_kjdfhskdjfhq387492834 .pdf' instead of 'folder_name/folder_name.pdf'.

If I check the store() function in UploadedFile it shows that it encryps it. But why? I want to know the real name of the file, can I create or use different functions to save files without encrypting the filename?

UploadedFile.php

    /**
     * Store the uploaded file on a filesystem disk.
     *
     * @param  string  $path
     * @param  array|string  $options
     * @return string|false
     */
    public function store($path, $options = [])
    {
        return $this->storeAs($path, $this->hashName(), $this->parseOptions($options));
    }

FileHelper.php

    /**
     * Get a filename for the file.
     *
     * @param  string|null  $path
     * @return string
     */
    public function hashName($path = null)
    {
        if ($path) {
            $path = rtrim($path, '/').'/';
        }

        $hash = $this->hashName ?: $this->hashName = Str::random(40);

        if ($extension = $this->guessExtension()) {
            $extension = '.'.$extension;
        }

        return $path.$hash.$extension;
    }
0 likes
2 replies

Please or to participate in this conversation.