Jump to content
  • 0

How to Limit File Size and Restrict File types from Upload


turner2f

Question

5 answers to this question

Recommended Posts

  • 0

if you want to use the UPLOAD class you can do like this

a sample how to like this :

// Load the pload components
Loader::loadComponents($this, ["Upload"]);
// Set the alloweded file types
$this->Upload->setAllowedMimeTypes(['gif','png','pdf']);
// Set the maximum file size
$this->Upload->setMaxFileSize(2048); // size in bytes
$this->Upload->setFiles($files, false); // the files list to upload
$this->Upload->setUploadPath("/home/user/upload_directory/"); // the upload path directory
// Will not overwrite existing file
// And we will support the uploaded files are in $files['data']
$this->Upload->writeFile("data", false);

// check if the upload was successfully 
if (!($errors = $this->Upload->errors())) {
	$this->Input->setErrors($errors);
    return;
}

 

 

Link to comment
Share on other sites

  • 0

@Blesta Addons

 

1)  - Exactly which folder and file do I place this code ?

 

2) - And where within the file ( top, bottom, middle ) ?
 

Quote

// Load the pload components
Loader::loadComponents($this, ["Upload"]);
// Set the alloweded file types
$this->Upload->setAllowedMimeTypes(['gif','png','pdf']);
// Set the maximum file size
$this->Upload->setMaxFileSize(2048); // size in bytes
$this->Upload->setFiles($files, false); // the files list to upload
$this->Upload->setUploadPath("/home/user/upload_directory/"); // the upload path directory
// Will not overwrite existing file
// And we will support the uploaded files are in $files['data']
$this->Upload->writeFile("data", false);

// check if the upload was successfully 
if (!($errors = $this->Upload->errors())) {
	$this->Input->setErrors($errors);
    return;
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...