/**
  * Uploads the images temporary to the cache folder
  * If the user doesn't save his entry the cron job will delete
  * the images
  *
  * @param   array  $file  - the file array
  *
  * @return boolean
  */
 public function uploadTmp($file)
 {
     $appl = JFactory::getApplication();
     // Total length of post back data in bytes.
     $contentLength = (int) $_SERVER['CONTENT_LENGTH'];
     $mediaHelper = new CompojoomHelperMedia();
     // Maximum allowed size of post back data in MB.
     $postMaxSize = $mediaHelper->toBytes(ini_get('post_max_size'));
     // Maximum allowed size of script execution in MB.
     $memoryLimit = $mediaHelper->toBytes(ini_get('memory_limit'));
     // Check for the total size of post back data.
     if ($postMaxSize > 0 && $contentLength > $postMaxSize || $memoryLimit != -1 && $contentLength > $memoryLimit) {
         $appl->enqueueMessage(JText::_('LIB_COMPOJOOM_ERROR_WARNUPLOADTOOLARGE'));
         return false;
     }
     // Do we have a file?
     if (isset($file['name'])) {
         JLoader::import('joomla.filesystem.file');
         $user = JFactory::getUser();
         $canUpload = $user->authorise('core.multimedia.create', $this->component);
         $params = JComponentHelper::getParams($this->component);
         $sizes = (array) $params->get('thumbs');
         // Some cameras just add whitespace, let's change this
         $file['name'] = str_replace(' ', '_', $file['name']);
         // Some users are uploading files with umlauts, change them to normal characters, otherwise we get an error on upload
         $file['name'] = preg_replace("/&([a-z])[a-z]+;/i", "\$1", htmlentities($file['name']));
         // The user doesn't seem to have upload privilegies
         if (!$canUpload) {
             $appl->enqueueMessage(JText::_('LIB_COMPOJOOM_YOU_DONT_HAVE_UPLOAD_PRIVILEGES'));
             return false;
         }
         // Check if we pass all other checks
         if (!$mediaHelper->canUpload($file, $this->component)) {
             return false;
         }
         // Get a (very!) randomised name
         $serverkey = JFactory::getConfig()->get('secret', '');
         $sig = microtime() . $serverkey;
         if (function_exists('sha256')) {
             $mangledname = sha256($sig);
         } elseif (function_exists('sha1')) {
             $mangledname = sha1($sig);
         } else {
             $mangledname = md5($sig);
         }
         $mangledname .= '_' . $file['name'];
         // ...and its full path
         $filepath = JPath::clean($this->getFilePath() . $mangledname);
         // If we have a name clash, abort the upload
         if (JFile::exists($filepath)) {
             $appl->enqueueMessage(JText::_('LIB_COMPOJOOM_ATTACHMENTS_ERR_NAMECLASH'));
             return false;
         }
         // Do the upload
         if (!JFile::upload($file['tmp_name'], $filepath)) {
             $appl->enqueueMessage(JText::_('LIB_COMPOJOOM_ATTACHMENTS_ERR_CANTJFILEUPLOAD'));
             return false;
         }
         // Get the MIME type
         if (function_exists('mime_content_type')) {
             $mime = mime_content_type($filepath);
         } elseif (function_exists('finfo_open')) {
             $finfo = finfo_open(FILEINFO_MIME_TYPE);
             $mime = finfo_file($finfo, $filepath);
         } else {
             $mime = 'application/octet-stream';
         }
         // Create a temporary thumb file
         $image = new CompojoomImage($filepath);
         $thumbs = $image->createThumbs($sizes['small']);
         $imageData = base64_encode(file_get_contents($thumbs[0]->getPath()));
         // Now remove the thumb
         JFile::delete($thumbs[0]->getPath());
         // Format the image SRC:  data:{mime};base64,{data};
         $src = 'data: ' . $mime . ';base64,' . $imageData;
         // Return the file info
         $fileData = array('name' => $mangledname, 'title' => JFile::stripExt($file['name']), 'thumbnailUrl' => $src, 'size' => $file['size'], 'type' => $file['type'], 'deleteType' => 'delete', 'url' => '', 'deleteUrl' => $this->deleteUrl . '&file=' . $mangledname);
         return $fileData;
     } else {
         $appl->enqueueMessage(JText::_('LIB_COMPOJOOM_ATTACHMENTS_ERR_NOFILE'));
         return false;
     }
 }
<script type="text/javascript">
	document.getElementById("file-upload-fake").addEventListener("click", function () {
		document.getElementById("file-upload-real").click();  // trigger the click of actual file upload button
	});

	jQuery(document).ready(function () {
		var $ = jQuery;

		// Initialize the jQuery File Upload widget:
		$('#fileupload').fileupload({
			// Uncomment the following to send cross-domain cookies:
			//xhrFields: {withCredentials: true},
			formData: {},
			autoUpload: true,
			maxFileSize: <?php 
echo $mediaHelper->toBytes($displayData['maxSize'] . 'M');
?>
,
			maxNumberOfFiles: <?php 
echo $displayData['maxNumberOfFiles'];
?>
,
			url: '<?php 
echo $displayData['url'] . '&' . JSession::getFormToken();
?>
=1',
			disableImageResize: false,
			imageMaxWidth: <?php 
echo $imageSize['x'];
?>
,