Skip to content

Commit

Permalink
Added support for form uploads that can now be attached to e.g. e-mai…
Browse files Browse the repository at this point in the history
  • Loading branch information
Toflar committed Jul 7, 2015
1 parent c2298af commit 2827166
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
7 changes: 7 additions & 0 deletions classes/tl_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace NotificationCenter;

use NotificationCenter\Util\Form;

class tl_form extends \Backend
{

Expand Down Expand Up @@ -88,6 +90,11 @@ public function generateTokens(array $arrData, array $arrForm, array $arrFiles,
// Administrator e-mail
$arrTokens['admin_email'] = $GLOBALS['TL_ADMIN_EMAIL'];

// Upload fields
foreach ($arrFiles as $fieldName => $file) {
$arrTokens['form_' . $fieldName] = Form::getFileUploadPathForToken($file);
}

return $arrTokens;
}

Expand Down
40 changes: 40 additions & 0 deletions library/NotificationCenter/Util/Form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/**
* notification_center extension for Contao Open Source CMS
*
* @copyright Copyright (c) 2008-2015, terminal42
* @author terminal42 gmbh <[email protected]>
* @license LGPL
*/


namespace NotificationCenter\Util;


class Form
{
/**
* Moves an uploaded file to the tmp folder and returns its TL_ROOT relative path.
* If it was not properly uploaded, the method will return null.
*
* @param array $file
* @return null|string
*/
public static function getFileUploadPathForToken(array $file)
{
if (!is_uploaded_file($file['tmp_name'])) {

return null;
}

$tmpDir = 'system/tmp';
$filePath = $tmpDir . '/' . $file['name'];

\Files::getInstance()->move_uploaded_file($file['tmp_name'], $filePath);
\Files::getInstance()->chmod($filePath, $GLOBALS['TL_CONFIG']['defaultFileChmod']);


return $filePath;
}
}

0 comments on commit 2827166

Please sign in to comment.