From The Smartest Wiki
Revision as of 01:19, 7 May 2016 by WikiAdmin (Talk | contribs) (Using the class with the uploaded data)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The SmartestUploadHelper class provides support for easy uploading of files to Smartest. It is used by all Smartest's internal file-uploading, but is also available as a public API.

Note that if you are creating a file in the media library you will need to pass an instance of this class to SmartestAssetCreationHelper::createNewAssetFromFileUpload().

Your HTML upload form

<form action="/your/upload/action/url" method="post" enctype="multipart/form-data">
  <input type="file" name="my_file_upload" />

When submitted, this form creates an upload within PHP called my_file_upload.

Using the class with the uploaded data

$upload = new SmartestUploadHelper('my_file_upload');
$upload->setUploadDirectory('Path/To/Where/You/Want/To/Store/The/File/'); // Note the trailing slash
$upload->setFileName('alternate.pdf'); // Will be the name of the original file unless you change it

if($upload->hasDotSuffix('pdf')){ // This is just to demonstrate that you can check file suffixes
  }catch(SmartestException $e){
    // Deal with any error here