FileUploadService
in package
Table of Contents
Properties
Methods
- __construct() : mixed
- convertSurveyIdWhenUniqUploadDir() : int|string
- If config param "uniq_upload_dir" is set to true, convert survey ID to 'uniq'
- getSurveyUploadDirectory() : string
- If not found, it creates the necessary directories.
- saveFileInDirectory() : array<string|int, mixed>
- This function will sanitize the filename to prevent potential security issues.
- storeSurveyImage() : array<string|int, mixed>|array<string|int, false>
- buildUrlPath() : mixed
- checkUpdatePermission() : void
- convertFullIntoRelativePath() : string
- Removes the configured "uploaddir" part from the path which results in the relative path
- getFilesFromDirectory() : array<string|int, mixed>
- Get all fileNames from a directory
- getFilesPathsFromDirectory() : array<string|int, mixed>
- Retrieves files from a directory and returns them in an associative array with filePath and previewPath for every single file.
- getPreviewPath() : string
- Logic will be added later, for images previewPath is the same as filePath
- getUploadPath() : mixed
- handleDuplicateFileName() : string
- Handles duplicate filenames in a directory by appending a numeric suffix (e.g., "(1)", "(2)").
- isDuplicateFile() : bool
- If a file with the same name exists in the path, this function will compare the new file with the existing one.
- rTrimPathSeparators() : mixed
- validateFileUpload() : null|string
Properties
$modelPermission
private
Permission
$modelPermission
$uploadValidator
private
UploadValidator
$uploadValidator
Methods
__construct()
public
__construct(UploadValidator $uploadValidator, Permission $modelPermission) : mixed
Parameters
- $uploadValidator : UploadValidator
- $modelPermission : Permission
convertSurveyIdWhenUniqUploadDir()
If config param "uniq_upload_dir" is set to true, convert survey ID to 'uniq'
public
convertSurveyIdWhenUniqUploadDir(int $surveyId) : int|string
Parameters
- $surveyId : int
Return values
int|stringgetSurveyUploadDirectory()
If not found, it creates the necessary directories.
public
getSurveyUploadDirectory(int|string $surveyId[, string $directoryName = 'images' ]) : string
Returns the path to the created directory.
Parameters
- $surveyId : int|string
- $directoryName : string = 'images'
Return values
stringsaveFileInDirectory()
This function will sanitize the filename to prevent potential security issues.
public
saveFileInDirectory(array<string|int, mixed> $fileInfoArray, string $destinationDir) : array<string|int, mixed>
Afterwards it will store the file into the destination directory.
Parameters
- $fileInfoArray : array<string|int, mixed>
- $destinationDir : string
Return values
array<string|int, mixed>storeSurveyImage()
public
storeSurveyImage(int|string $surveyId, array<string|int, mixed> $fileInfoArray) : array<string|int, mixed>|array<string|int, false>
Parameters
- $surveyId : int|string
- $fileInfoArray : array<string|int, mixed>
Return values
array<string|int, mixed>|array<string|int, false>buildUrlPath()
private
buildUrlPath(mixed $parts) : mixed
Parameters
- $parts : mixed
checkUpdatePermission()
private
checkUpdatePermission( $surveyId) : void
Parameters
Tags
convertFullIntoRelativePath()
Removes the configured "uploaddir" part from the path which results in the relative path
private
convertFullIntoRelativePath(string $filePath) : string
Parameters
- $filePath : string
Return values
stringgetFilesFromDirectory()
Get all fileNames from a directory
private
getFilesFromDirectory(string $directory, int $surveyId) : array<string|int, mixed>
Parameters
- $directory : string
- $surveyId : int
Return values
array<string|int, mixed>getFilesPathsFromDirectory()
Retrieves files from a directory and returns them in an associative array with filePath and previewPath for every single file.
private
getFilesPathsFromDirectory(string $directory, int $surveyId) : array<string|int, mixed>
Parameters
- $directory : string
- $surveyId : int
Return values
array<string|int, mixed>getPreviewPath()
Logic will be added later, for images previewPath is the same as filePath
private
getPreviewPath(string $filePath) : string
Parameters
- $filePath : string
Return values
stringgetUploadPath()
private
getUploadPath() : mixed
handleDuplicateFileName()
Handles duplicate filenames in a directory by appending a numeric suffix (e.g., "(1)", "(2)").
private
handleDuplicateFileName(string $fileName, string $path) : string
This function checks if a file with the given filename exists in the specified directory. If it does, it renames the file by appending a numeric suffix, incrementing the number until a unique filename is found, mimicking Windows Explorer behavior.
Parameters
- $fileName : string
-
The name of the file to check for duplicates (e.g., "example.txt").
- $path : string
-
The directory path where the file resides.
Return values
string —A unique filename with no conflicts in the given directory.
isDuplicateFile()
If a file with the same name exists in the path, this function will compare the new file with the existing one.
private
isDuplicateFile(array<string|int, mixed> $fileInfoArray, string $path) : bool
If those two files are identical, it will return true.
Parameters
- $fileInfoArray : array<string|int, mixed>
-
The array containing the file and name.
- $path : string
-
The directory path where the file resides.
Return values
boolrTrimPathSeparators()
private
rTrimPathSeparators(mixed $path) : mixed
Parameters
- $path : mixed
validateFileUpload()
private
validateFileUpload(int|string $surveyId, array<string|int, mixed> $fileInfoArray, string $destinationDir) : null|string
Parameters
- $surveyId : int|string
- $fileInfoArray : array<string|int, mixed>
- $destinationDir : string