WebFioriAPI ReferenceLearnDownloadContributeLearn{{result.parent_page}} > {{result.title}}{{result.title}}Classes{{result.class_name}}{{result.summary}}Methods{{result.name}}{{result.summary}}

namespace \webfiori\framework

class Uploader

Class Attributes Summary

const NOT_ALLOWEDA constant that is used to indicates uploaded file type is not allowed.const NO_SUCH_DIRA constant that is used to indicates upload directory does not exists.const NO_SUCH_FILEA constant that is used to indicates that a file does not exists.const UPLOAD_ERR_EXT_NOT_ALLOWEDA constant to indicate that a file type is not allowed to be uploaded.const UPLOAD_ERR_FILE_ALREADY_EXISTA constant to indicate that a file already exist in upload directory.

Class Methods Summary

public function __construct(string$uploadPath, array$allowedTypes)Creates new instance of the class.public function __toString()Returns a JSON string that represents the object.public function addExt(string$ext)Adds new extension to the array of allowed files types.public function addExts(array$arr)Adds multiple extensions at once to the set of allowed files types.public function getAssociatedFileName()Returns the name of the index at which the uploaded files will exist on in the array $_FILES.public function getExts()Returns the array that contains all allowed file types.public function getFiles(boolean$asObj)Returns an array which contains all information about the uploaded files.public function getUploadDir()Returns the directory at which the file or files will be uploaded to.public function removeExt(string$ext)Removes an extension from the array of allowed files types.public function setAssociatedFileName(string$name)Sets The name of the index at which the file is stored in the array $_FILES.public function setUploadDir(string$dir)Sets the directory at which the file will be uploaded to.public function toJSON()Returns a JSON representation of the object.public function upload(bolean$replaceIfExist)Upload the file to the server.public function uploadAsFileObj(bolean$replaceIfExist)Returns an array that contains objects of type 'UploadedFile'.

Class Attributes Details

const NOT_ALLOWEDA constant that is used to indicates uploaded file type is not allowed. const NO_SUCH_DIRA constant that is used to indicates upload directory does not exists. It usually returned by some methods as error code.const NO_SUCH_FILEA constant that is used to indicates that a file does not exists. const UPLOAD_ERR_EXT_NOT_ALLOWEDA constant to indicate that a file type is not allowed to be uploaded. const UPLOAD_ERR_FILE_ALREADY_EXISTA constant to indicate that a file already exist in upload directory.

Class Methods Details

public function __construct(string$uploadPath, array$allowedTypes)Creates new instance of the class.

Parameters:

  • string $uploadPath A string that represents the location at which files will be uploaded to. Default value is 'app/sto/uploads'.
  • array $allowedTypes An array that contains allowed files types. The array can have values such as 'jpg', 'png', 'doc', etc...
public function __toString()
Returns a JSON string that represents the object. The string will be something the the following:
      {        "upload-directory":"",        "allowed-types":[],        "files":[],        "associated-file-name":""      }      
Returns: stringA JSON string.
public function addExt(string$ext)Adds new extension to the array of allowed files types.

Parameters:

  • string $ext File extension (e.g. jpg, png, pdf).
Returns: booleanIf the extension is added, the method will return true.
public function addExts(array$arr)Adds multiple extensions at once to the set of allowed files types.

Parameters:

  • array $arr An array of strings. Each string represents a file type.
Returns: arrayThe method will return an associative array of booleans. The key value will be the extension name and the value represents the status of the addition. If added, it well be set to true.
public function getAssociatedFileName()Returns the name of the index at which the uploaded files will exist on in the array $_FILES. This value represents the value of the attribute 'name' of the files input in case of HTML forms.Returns: stringthe name of the index at which the uploaded files will exist on in the array $_FILES. Default value is 'files'.public function getExts()Returns the array that contains all allowed file types. Returns: array public function getFiles(boolean$asObj)
Returns an array which contains all information about the uploaded files. The returned array will be indexed. At each index, a sub associative array that holds uploaded file information. Each array will have the following indices:
  • name: The name of the uploaded file.
  • size: The size of the uploaded file in bytes.
  • upload-path: The location at which the file was uploaded to in the server.
  • upload-error: Any error which has happend during upload.
  • is-exist: A boolean. Set to true if the file does exist in the server.
  • is-replace: A boolean. Set to true if the file was already uploaded and replaced.
  • mime: MIME type of the file.
  • uploaded: A boolean. Set to true if the file was uploaded.

Parameters:

  • boolean $asObj If this parameter is set to true, the returned array will contain objects of type 'UploadedFile' instead of sub associative arrays. Default value is true.
Returns: arrayAn indexed array that contains sub associative arrays or objects of type 'UploadFile'.
public function getUploadDir()Returns the directory at which the file or files will be uploaded to. Returns: stringupload directory.public function removeExt(string$ext)Removes an extension from the array of allowed files types.

Parameters:

  • string $ext File extension= (e.g. jpg, png, pdf,...).
Returns: booleanIf the extension was removed, the method will return true.
public function setAssociatedFileName(string$name)Sets The name of the index at which the file is stored in the array $_FILES. This value is the value of the attribute 'name' in case of HTML file input. It is possible to set the value of the property in the front end by using a hidden input field with name = 'file' and the value of that input field must be the value of the attribute 'name' of the original file input. In case of API call, it can be supplied as a POST parameter with name 'file'.

Parameters:

  • string $name The name of the index at which the file is stored in the array $_FILES. input element.
public function setUploadDir(string$dir)Sets the directory at which the file will be uploaded to. This method does not check whether the directory is exist or not. It just validate that the structure of the path is valid by replacing forward slashes with backward slashes. The directory will never update if the given string is empty.

Parameters:

  • string $dir Upload Directory (such as '/files/uploads' or 'C:/Server/uploads').
Returns: booleanIf upload directory was updated, the method will return true. If not updated, the method will return false.
public function toJSON()Returns a JSON representation of the object. Returns: Jsonan object of type Jsonpublic function upload(bolean$replaceIfExist)Upload the file to the server.

Parameters:

  • bolean $replaceIfExist If a file with the given name found and this parameter is set to true, the file will be replaced.
Returns: arrayAn array which contains uploaded files info. Each index will contain an associative array which has the following info:
  • name: The name of uploaded file.
  • size: The size of uploaded file in bytes.
  • upload-path: The location at which the file was uploaded to in the server.
  • upload-error: A string that represents upload error.
  • is-exist: A boolean. Set to true if the file was found in the server.
  • is-replace: A boolean. Set to true if the file was exist and replaced.
  • mime: MIME type of the file.
  • uploaded: A boolean. Set to true if the file was uploaded.
public function uploadAsFileObj(bolean$replaceIfExist)Returns an array that contains objects of type 'UploadedFile'.

Parameters:

  • bolean $replaceIfExist If a file with the given name found and this parameter is set to true, the file will be replaced.
Returns: arrayAn array that contains objects of type 'UploadedFile'.
mdi-menuAll Classesmdi-chevron-leftAnchorBrCodeSnippetHTMLDocHTMLListHTMLNodeHTMLTableHeadNodeInputJsCodeLabelListItemOrderedListParagraphRadioGroupTableCellTableRowUnorderedListInvalidNodeNameExceptionTemplateNotFoundExceptionCaseConverterJsonJsonConverterJsonIJsonTypesPropertyAPIFilterAbstractWebServiceManagerInfoServiceParamTypesRequestRequestParameterResponseUriWebServicesManagerAccessAutoLoaderConfigConfigControllerDBEAbstractWebServiceExtendedWebServicesManagerFileLoggerPrivilegePrivilegesGroupThemeThemeLoaderUploadFileUploaderUserUtilWebFioriAppLanguageErrorBoxHTTPCodeViewMessageBoxServerErrViewStarterPageWebPageDatabaseSessionStorageDefaultSessionStorageMSSQLSessionDataTableMSSQLSessionsTableMySQLSessionDataTableMySQLSessionsTableSessionSessionOperationsSessionStorageSessionsManagerRouterRouterUriAbstractMiddlewareMiddlewareManagerEmailMessageSMTPAccountSMTPServerClassLoaderExceptionFileExceptionInitializationExceptionInvalidCRONExprExceptionMissingLangExceptionNoSuchThemeExceptionRoutingExceptionSMTPExceptionSessionExceptionUIExceptionAbstractJobCronCronEmailCronJobJobArgumentCronLoginViewCronTasksViewCronViewCronLoginServiceCronLogoutServiceCronServicesManagerForceCronExecutionServiceGetJobsServiceCLICLICommandInputStreamOutputStreamStdInStdOutClassWriterLangClassWriterQueryClassWriterServiceHolderThemeClassWriterWebServiceWriterCreateCLIClassHelperCreateCronJobCreateMiddlewareCreateTableCreateTableObjCreateThemeHelperCreateWebServiceAddCommandCreateCommandCronCommandHelpCommandListCronCommandListRoutesCommandListThemesCommandRunSQLQueryCommandSettingsCommandTestRouteCommandUpdateSettingsCommandUpdateTableCommandVersionCommandAbstractQueryColumnColumnFactoryConditionConnectionConnectionInfoDatabaseDatabaseExceptionDateTimeValidatorEntityMapperExpressionForeignKeyJoinTableResultSetSelectExpressionTableWhereExpressionMySQLColumnMySQLConnectionMySQLQueryMySQLTableMSSQLColumnMSSQLConnectionMSSQLQueryMSSQLTableAbstractCollectionComparableLinkedListNodeQueueStack
Powered By: WebFiori Framework, Vue and VuetifyAll Rights Reserved © 2018 - 2024