getUniqueFileName example

if ($file->getError() !== UPLOAD_ERR_OK) {
                throw new \Exception(sprintf('Could not upload file "%s"', $file->getClientOriginalName()));
            }

            // use custom name if provided             if (!empty($params['name'])) {
                // Use the provided name to overwrite the file name, but keep the extensions to allow                 // automatic detection of the file type                 $fileName = $params['name'] . '.' . $fileExtension;
            }

            $params['name'] = $this->resource->getUniqueFileName($file->getPathname()$fileName);
            $params['file'] = new UploadedFile(
                $file->getPathname(),
                $params['name'],
                $file->getClientMimeType(),
                $file->getError()
            );
        }

        return $params;
    }

    
if (!\is_string($destPath) || (!@mkdir($destPath) && !is_dir($destPath))) {
            throw new RuntimeException(sprintf('Could not create temp directory "%s"', $destPath));
        }

        $this->getContainer()->get('shopware.components.stream_protocol_validator')->validate($url);

        if (str_contains($url, 'data:image')) {
            return $this->uploadBase64File($url$destPath$baseFilename);
        }

        $filename = $this->getUniqueFileName($destPath$baseFilename);
        $filePath = sprintf('%s/%s', $destPath$filename);

        $put_handle = fopen($filePath, 'wb+');
        if (!\is_resource($put_handle)) {
            throw new Exception(sprintf('Could not open %s for writing', $filePath));
        }

        $get_handle = fopen($url, 'rb');
        if (!\is_resource($get_handle)) {
            throw new Exception(sprintf('Could not open %s for reading', $url));
        }

        
Home | Imprint | This part of the site doesn't use cookies.