1. The 3.8 code for Fabrik is now available on github, in the 'master' branch. If you are familiar with updating Fabrik from github, we would appreciate it if you could test this code on J! 3.8 for us. Once we have some feedback, we'll build a 3.8 release.

File Upload element

Oct 6, 2015
File Upload element
  • The fileupload element allows you to upload files to the server, or to an amazon account. It also allows you to upload multiple files at a time, via an ajax upload. If you use this option and you have the maximum number of allowed files set to more than one, then the data for each uploaded file is stored in individual rows in a 'linked' table called, 'originaltable_repeat_elementname'


    Options (top)
    [​IMG]
    • Maximum file size - The maximum file size in Kb of any file uploaded by this element
    • Allowed file types - A comma separated list of file extensions that are allowed by the element,
      E.g.
      Code (Text):
      .png, .jpeg, .gif
      Leave blank to use Joomla's default list of allowed file extension
    • Upload directory - the folder into which the uploaded files can be stored. Path to upload directory (eg images/stories/). Passed through replacement code, so images/stories/{$my->id} would be replaced with the current user's id. Other placeholders: {date} and {myql_date} will work, {tablename___element} will only work when not using ajax uploads.
    • Email uploaded file to recipients - If set to yes then the uploaded files are attached to any email's sent by the form's email plug-in
    • Obfuscate Filename - Adds a random series of numbers or letters onto the end of the filename
    • Length random filename - the number of random characters to add to the file name when 'obfuscate filename' selected
    • If existing image found?
      • Leave original file - the newly uploaded file will not be stored on the server
      • Leave original file and increment new file's name - the original file will be left on the server and the newly uploaded file's name will be amended (each new file name will be pre-pended with the version number)
    • Allow subfolder selection - If set to yes then a drop down appears next to the upload element field, from which the user can select which sub folder to upload the file into.
    • Delete images? - If set to yes, then if a record is deleted from a Fabrik table the files contained within that record are also deleted from the server. If set to no then the files are left on the server.
    Display (top)
    • Default image - Enter the path to a image to display if none currently available
    • Link to file - Create a link to the file when in the table view. Required if you want to use a lightbox in the table view.
    • Show media in table - If set to yes then Fabrik will show the media in the table. Depending upon the media type this may be an image, flash, video or a icon representing a document.
    • Show media in form-similar to 'show media in table' except you additionally have the option to show the thumbnail
      • no
      • thumbnail - (If thumbnails not set to be created, then this will show the full sized image
      • full size
    • Image library - The image library you wish to use to process images with (used when resizing and cropping any uploaded images)
    • Max width - When uploading images this specifies the maximum width in pixels that that image can be, if the uploaded image is wider than this value the main image is scaled down so that its width is no greater than this value.
    • Max height - When uploading images this specifies the maximum height in pixels that that image can be, if the uploaded image is higher than this value the main image is scaled down so that its height is no greater than this value.
    • Title element - If either 'show media in form' or 'show media in table' selected then the data contained within the title element will be used in the lightbox title.
    • Use download script - If selected, the link to the file will be a download script, forcing the browser to download the file rather than performing the normal MIME type based action. This option overrides other display options like Show Media In Form / Table. If a Title Element is specified, this will be used as the link title, otherwise the filename will be used. You have the option to specify this for the table view, detailed view or for both.
    Thumbnail (top)
    [​IMG]
    • Make a thumbnail of the uploaded image - If set to yes and an image uploaded then a thumbnail image is also created. This image is used in preference to the main image when rendering data in the table, form and detailed views.
    • Thumbnail directory - the directory to store the thumbnail images in
    • Thumbnail prefix - the prefix to attach the the thumbnail image name
    • Thumbnail width - When creating the thumbnail this specifies the maximum width in pixels that the thumbnail can be, if the thumbnail is wider than this value the main image is scaled down so that its width is no greater than this value.
    • Thumbnail height - When creating the thumbnail this specifies the maximum height in pixels that that image can be, if the thumbnail is higher than this value the thumbnail is scaled down so that its height is no greater than this value.
    Crop (top)

    Note crop will not work with IE 8 or less
    • Crop - If yes selected then when editing a record, an interface is presented which allows you to drag the main image around to create a cropped version
    • Cropdir - the directory in which to save the cropped images
    • Cropwidth - the width of the cropped image
    • Cropheight - the cropped image height
    Storage (top)

    • Storage type -
      • Filesystem - Your files will be stored on your server.
      • Amazon s3 - Your files will be stored in Amazon's S3 cloud storage service
    • Amazon s3 access key id - Get this information when you sign up for an S3 account
    • Amazon s3 secret key - Get this information when you sign up for an S3 account
    • Amazon storage location - Select the geographical area which is closest to the majority of your users
    • Bucket name - A bucket is Amzon's terminology for a folder, select the name of the bucket you want to store the files in
    • Use AJAX upload - allows to upload multiple files at a time (and per row). An additional database table yourtable_repeat_yourelement will be created when ajax mode is choosen.
      NOTE! Until a good solution is found the fileupload element in ajax mode doesn't work within any joined group, repeated or not.

    Downloads (top)

    [​IMG]
    • Use download script -
    • Access element' -
    • No access image -
    • No access url -
    • Access image -
    • Hit counter -
    • Log downloads -
    Export (top)
    • CSV formatDetermines how to present the fileupload data when exporting to csv:
      • Relative path - e.g. images/stories/myimage.jpg
      • Full path e.g. /var/www/html/images/stories/myimage.jpg
      • Raw file stream - the binary data returned from JFile::read()
      • Base 64 encoded file stream - a base64 encoded version of the raw file stream
    • JSON format - same as the CSV format except for when viewing the table data as JSON (Javascript Object Notation)
    Example - File rename on upload (top)

    • This is an example of one way to rename a file on upload (this example assumes Fabrik 3.1+)
    • In a php form plugin add the following to the onBeforeCalculations event (or a later event):
    • You can adjust the values to meet your needs - this is just one possible example
    PHP:
    // use Joomla file utils
    jimport( 'joomla.filesystem.file' );
    // get the original file and split it into parts
    $old = ($formModel->formData['file']);
    $oldParts = pathinfo($old);
    // in this example we're using the id as the new filename
    $sid = $formModel->formData['id'];
    //create the new file (path and name)
    $new = $oldParts['dirname'].'/'.$sid.'.'.$oldParts['extension'];
    // update the file itself
    JFile::move(JPATH_SITE.$old, JPATH_SITE.$new);
    // update the data
    $formModel->updateFormData('file', $new, true);
    // update the db
    $object = new stdClass();
    // Must be a valid primary key value.
    $object->id = $sid;
    // new path + name
    $object->file = $new;
    // Update the data in the db
    $result = JFactory::getDbo()->updateObject('ep_submission', $object, 'id');
    Example: File upload with full word indexing for search(top)


    Apache Tika is a free utility that will read a variety of document formats and return the text content from them in a variety of formats (text, xml, json, etc). This is a form plug in uses Tika to extract index keywords (text) from a uploaded document. The extracted text will be placed into a textarea element and also updated to the database record. This allows any document type supported by Tika to be indexed using MySQL fulltext indexing.

    Apache Tika is available for free download
    It requires Java be installed on the server (see Apache Tika site for details)
    Experiment at the command line to ensure that tika-app.jar will run using the syntax shown below in the code example below.
    This example uses the Tika runnable jar file to perform the text extraction. There are other integration options.
    • Apache Tika is available for free download. You want tika-app.jar for this example
    • It requires Java be installed on the server (see Apache Tika site for details)
    • Experiment at the command line to ensure that tika-app.jar will run using the syntax shown below in the code example below
    • This example uses the Tika runnable jar file to perform the text extraction. There are other integration options
    • Use a Fabrik textarea element to store the tika generated text
    • Depending in size of text generated by Tika from your documents, you may need to change the column type in MySQL Admin (alter table) to mediumtext, largetext, etc., to accomodate the larger text size.
    • For filtering and searching based on these fulltext key words, add your element that stores the full text content to the List where this textarea resides and using Lists > Details > Filters, add the textarea to the "Elements" field and set "Search All" to "Yes"
    • Now, just enter any word from any uploaded document that Tika supports and it will be filtered to just that word
    PHP:

    /* 11/30/2014 by pastne - based on wiki form plug-in example
    Plug-in to re-read submitted file from disk
    then run it through apache tika to retrieve text of document
    then update the form field and database with the tika
    generated full text.  This will cause the database to
    index based on fulltext indexing. This plug-in fires
    after file upload has landed on disk.
    */

    // import the joomla file system
    jimport( 'joomla.filesystem.file' );
    //grab the filename from the form (my element name is filename)
    $filePath = JPATH_ROOT . ($formModel->formData['filename']);

    //set the full path to the tika-app.jar java run program (this is where I put the jar)
    $tikaAppPath = '/var/www/html/tika-app.jar';

    //build a command command string with expansion
    $command = "((cat '"  . $filePath . "' | java -jar $tikaAppPath --text) 2>&1)";

    //execute the command and capture out to $execOutArray
    $status = exec( $command, $execOutArray );

    //convert the output array  to compact space delimited trimmed string
    $execOut = preg_replace('/\s\s+/', ' ', implode(' ', $execOutArray));

    //grab the database record id
    $sid = $formModel->formData['id'];

    //update the fullText form element with the trimmed Tika text
    $formModel->updateFormData('fullText', $execOut, true);

    // instantiate a new database object
    $object = new stdClass();
    // set the key for the database record to the value of $sid
    $object->id = $sid;
    // set the fullText element of the object to the tika trimmed result
    $object->fullText = $execOut;
    //push the updated object to the database using the Joomla JFactory class (my list name is fmp_msds)
    $result = JFactory::getDbo()->updateObject('fmp_msds', $object, 'id');
     
    Tips(top)
    When uploading many files at the same time try turning 'Enable big selects' to Yes.