コード例 #1
0
ファイル: MediaManager.php プロジェクト: Aziz-JH/core
 /**
  * Validate the upload
  * @return string
  */
 public function validateUpload()
 {
     \Message::reset();
     $objUploader = new \FileUpload();
     $objUploader->setName($this->strName);
     $uploadFolder = $this->strTempFolder;
     // Convert the $_FILES array to Contao format
     if (!empty($_FILES[$this->strName])) {
         $pathinfo = pathinfo(strtolower($_FILES[$this->strName]['name']));
         $strCacheName = standardize($pathinfo['filename']) . '.' . $pathinfo['extension'];
         $uploadFolder = $this->strTempFolder . '/' . substr($strCacheName, 0, 1);
         if (is_file(TL_ROOT . '/' . $uploadFolder . '/' . $strCacheName) && md5_file(TL_ROOT . '/' . $uploadFolder . '/' . $_FILES[$this->strName]['name']) != md5_file(TL_ROOT . '/' . $uploadFolder . '/' . $strCacheName)) {
             $strCacheName = standardize($pathinfo['filename']) . '-' . substr(md5_file(TL_ROOT . '/' . $uploadFolder . '/' . $_FILES[$this->strName]['name']), 0, 8) . '.' . $pathinfo['extension'];
             $uploadFolder = $this->strTempFolder . '/' . substr($strCacheName, 0, 1);
         }
         \Haste\Haste::mkdirr($uploadFolder);
         $arrFallback = $this->getFallbackData();
         // Check that image is not assigned in fallback language
         if (is_array($arrFallback) && in_array($strCacheName, $arrFallback)) {
             $this->addError($GLOBALS['TL_LANG']['ERR']['imageInFallback']);
         }
         $_FILES[$this->strName] = array('name' => array($strCacheName), 'type' => array($_FILES[$this->strName]['type']), 'tmp_name' => array($_FILES[$this->strName]['tmp_name']), 'error' => array($_FILES[$this->strName]['error']), 'size' => array($_FILES[$this->strName]['size']));
     }
     $varInput = '';
     try {
         $varInput = $objUploader->uploadTo($uploadFolder);
     } catch (\Exception $e) {
         $this->addError($e->getMessage());
     }
     if ($objUploader->hasError()) {
         foreach ($_SESSION['TL_ERROR'] as $strError) {
             $this->addError($strError);
         }
     }
     \Message::reset();
     if (!is_array($varInput) || empty($varInput)) {
         $this->addError($GLOBALS['TL_LANG']['MSC']['mmUnknownError']);
     }
     return $varInput[0];
 }
コード例 #2
0
$userManager = new ManageUser($db);
$sesion = new Session();
$email = Request::post("email");
$newemail = Request::post("newemail");
$pass = Request::post("pass");
$alive = Request::post("alive");
$worker = Request::post("worker");
$admin = Request::post("admin");
$newemail = $newemail === null ? $email : $newemail;
$alive = $alive === null ? 0 : 1;
$worker = $worker === null ? 0 : 1;
$admin = $admin === null ? 0 : 1;
$usuario = $userManager->get($email);
$usuario->setEmail($newemail);
$usuario->setAlias(explode("@", $newemail)[0]);
$usuario->setAlive($alive);
$usuario->setWorker($worker);
$usuario->setAdmin($admin);
if ($pass !== null) {
    $usuario->setPass($pass);
}
$photo = new FileUpload("image");
if ($photo->getError() === false) {
    $usuario->setImage("images/" . $usuario->getAlias() . ".jpg");
    $photo->setDestination("../images/");
    $photo->setName($usuario->getAlias());
    echo $photo->upload();
}
$userManager->setEmail($usuario, $email);
$sesion->destroy();
$sesion->sendRedirect("../admin.php");
コード例 #3
0
 /**
  * Validate the upload
  * @return string
  */
 public function validateUpload()
 {
     \Message::reset();
     $strTempName = $this->strName . '_upload';
     $objUploader = new \FileUpload();
     $objUploader->setName($this->strName);
     // Convert the $_FILES array to Contao format
     if (!empty($_FILES[$strTempName])) {
         $arrFile = array('name' => array($_FILES[$strTempName]['name']), 'type' => array($_FILES[$strTempName]['type']), 'tmp_name' => array($_FILES[$strTempName]['tmp_name']), 'error' => array($_FILES[$strTempName]['error']), 'size' => array($_FILES[$strTempName]['size']));
         // Check if the file exists
         if (file_exists(TL_ROOT . '/' . $this->strTemporaryPath . '/' . $arrFile['name'][0])) {
             $arrFile['name'][0] = $this->getFileName($arrFile['name'][0], $this->strTemporaryPath);
         }
         $_FILES[$this->strName] = $arrFile;
         unset($_FILES[$strTempName]);
         // Unset the temporary file
     }
     $varInput = '';
     $maxlength = null;
     // Override the default maxlength value
     if (isset($this->arrConfiguration['maxlength'])) {
         $maxlength = $GLOBALS['TL_CONFIG']['maxFileSize'];
         $GLOBALS['TL_CONFIG']['maxFileSize'] = $this->getMaximumFileSize();
     }
     try {
         $varInput = $objUploader->uploadTo($this->strTemporaryPath);
         if ($objUploader->hasError()) {
             foreach ($_SESSION['TL_ERROR'] as $strError) {
                 $this->addError($strError);
             }
         }
         \Message::reset();
     } catch (\Exception $e) {
         $this->addError($e->getMessage());
     }
     // Restore the default maxlength value
     if ($maxlength !== null) {
         $GLOBALS['TL_CONFIG']['maxFileSize'] = $maxlength;
     }
     if (!is_array($varInput) || empty($varInput)) {
         $this->addError($GLOBALS['TL_LANG']['MSC']['avatar_error']);
     }
     $varInput = $varInput[0];
     $strExtension = pathinfo($varInput, PATHINFO_EXTENSION);
     $arrAllowedTypes = trimsplit(',', strtolower($this->getAllowedExtensions()));
     // File type not allowed
     if (!in_array(strtolower($strExtension), $arrAllowedTypes)) {
         $this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['filetype'], $strExtension));
     }
     // Check image size
     if (($arrImageSize = @getimagesize(TL_ROOT . '/' . $varInput)) !== false) {
         // Image exceeds maximum image width
         if ($arrImageSize[0] > $GLOBALS['TL_CONFIG']['imageWidth']) {
             $this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['filewidth'], '', $GLOBALS['TL_CONFIG']['imageWidth']));
         }
         // Image exceeds maximum image height
         if ($arrImageSize[1] > $GLOBALS['TL_CONFIG']['imageHeight']) {
             $this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['fileheight'], '', $GLOBALS['TL_CONFIG']['imageHeight']));
         }
         // Image exceeds minimum image width
         if ($arrImageSize[0] < $this->arrAvatarSize[0]) {
             $this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['avatar_width'], $this->arrAvatarSize[0]));
         }
         // Image exceeds minimum image height
         if ($arrImageSize[1] < $this->arrAvatarSize[1]) {
             $this->addError(sprintf($GLOBALS['TL_LANG']['ERR']['avatar_height'], $this->arrAvatarSize[1]));
         }
     }
     return $varInput;
 }
コード例 #4
0
 /**
  * Validate the upload
  * @return string
  */
 public function validateUpload()
 {
     \Message::reset();
     $strTempName = $this->strName . '_fineuploader';
     $objUploader = new \FileUpload();
     $objUploader->setName($this->strName);
     $blnIsChunk = isset($_POST['qqpartindex']);
     // Convert the $_FILES array to Contao format
     if (!empty($_FILES[$strTempName])) {
         $arrFile = array('name' => array($_FILES[$strTempName]['name']), 'type' => array($_FILES[$strTempName]['type']), 'tmp_name' => array($_FILES[$strTempName]['tmp_name']), 'error' => array($_FILES[$strTempName]['error']), 'size' => array($_FILES[$strTempName]['size']));
         // Set the UUID as the filename
         if ($blnIsChunk) {
             $arrFile['name'][0] = \Input::post('qquuid') . '.chunk';
         }
         // Check if the file exists
         if (file_exists(TL_ROOT . '/' . $this->strTemporaryPath . '/' . $arrFile['name'][0])) {
             $arrFile['name'][0] = $this->getFileName($arrFile['name'][0], $this->strTemporaryPath);
         }
         $_FILES[$this->strName] = $arrFile;
         unset($_FILES[$strTempName]);
         // Unset the temporary file
     }
     $varInput = '';
     $extensions = null;
     $maxlength = null;
     // Add the "chunk" extension to upload types
     if ($blnIsChunk) {
         $extensions = $GLOBALS['TL_CONFIG']['uploadTypes'];
         $GLOBALS['TL_CONFIG']['uploadTypes'] .= ',chunk';
     }
     // Override the default maxlength value
     if (isset($this->arrConfiguration['maxlength'])) {
         $maxlength = $GLOBALS['TL_CONFIG']['maxFileSize'];
         $GLOBALS['TL_CONFIG']['maxFileSize'] = $this->arrConfiguration['maxlength'];
     }
     try {
         $varInput = $objUploader->uploadTo($this->strTemporaryPath);
         if ($objUploader->hasError()) {
             foreach ($_SESSION['TL_ERROR'] as $strError) {
                 $this->addError($strError);
             }
         }
         \Message::reset();
     } catch (\Exception $e) {
         $this->addError($e->getMessage());
     }
     // Restore the default maxlength value
     if ($maxlength !== null) {
         $GLOBALS['TL_CONFIG']['maxFileSize'] = $maxlength;
     }
     // Restore the default extensions value
     if ($extensions !== null) {
         $GLOBALS['TL_CONFIG']['uploadTypes'] = $extensions;
     }
     if (!is_array($varInput) || empty($varInput)) {
         $this->addError($GLOBALS['TL_LANG']['MSC']['fineuploader_error']);
     }
     $varInput = $varInput[0];
     // Store the chunk in the session for further merge
     if ($blnIsChunk) {
         $_SESSION[$this->strName . '_FINEUPLOADER_CHUNKS'][\Input::post('qqfilename')][] = $varInput;
         // This is the last chunking request, merge the chunks and create the final file
         if (\Input::post('qqpartindex') == \Input::post('qqtotalparts') - 1) {
             $strFileName = \Input::post('qqfilename');
             // Get the new file name
             if (file_exists(TL_ROOT . '/' . $this->strTemporaryPath . '/' . $strFileName)) {
                 $strFileName = $this->getFileName($strFileName, $this->strTemporaryPath);
             }
             $objFile = new \File($this->strTemporaryPath . '/' . $strFileName);
             // Merge the chunks
             foreach ($_SESSION[$this->strName . '_FINEUPLOADER_CHUNKS'][\Input::post('qqfilename')] as $strChunk) {
                 $objFile->append(file_get_contents(TL_ROOT . '/' . $strChunk), '');
                 // Delete the file
                 \Files::getInstance()->delete($strChunk);
             }
             $objFile->close();
             $varInput = $objFile->path;
         }
     }
     return $varInput;
 }
コード例 #5
0
ファイル: sas_subir.php プロジェクト: ealvarez1990/sas
echo Filtrar::isInt($mes);
echo Filtrar::isInt($anio);
echo Filtrar::isInt($Tipo_Id);
if (Server::getRequestDate("Y") - $anio >= 14) {
    if ($dni == NULL || $dni == "") {
        echo "Documento de identidad obligatorio";
    }
}
if (strlen($id_us) <= 8) {
    echo "Nº de Tarjeta Sanitaria: incorrecto";
}
if ($dia < 1 || $dia > 31) {
    echo "Dias entre 1-31";
}
if ($mes < 1 || $mes > 12) {
    echo "Mes entre 1-12";
}
if (strlen($anio) < 4) {
    echo "Año debe tener 4 cifras";
}
if (strlen($dni) < 9) {
    echo "DNI debe tenr nueve caracteres";
}
$imagen = new FileUpload("archivo");
$imagen->setStore("img/");
$nombreOriginal = $imagen->getName();
$imagen->setName("_U_" . $usuario . "_X_" . $categoria . "_T_" . $privada . "_C_" . $nombreOriginal);
$imagen->getPolicy(FileUpload::RENAME);
$imagen->addType("gif");
$imagen->setSize(52428800);
var_dump($imagen);
コード例 #6
0
ファイル: GcHelpers.php プロジェクト: Aiod/gallery_creator
 /**
  * move uploaded file to the album directory
  *
  * @param $intAlbumId
  * @param string $strName
  * @return array
  */
 public static function fileupload($intAlbumId, $strName = 'file')
 {
     $blnIsError = false;
     // Get the album object
     $objAlb = \GalleryCreatorAlbumsModel::findById($intAlbumId);
     if ($objAlb === null) {
         $blnIsError = true;
         \Message::addError('Album with ID ' . $intAlbumId . ' does not exist.');
     }
     // Check for a valid upload directory
     $objUploadDir = \FilesModel::findByUuid($objAlb->assignedDir);
     if ($objUploadDir === null || !is_dir(TL_ROOT . '/' . $objUploadDir->path)) {
         $blnIsError = true;
         \Message::addError('No upload directory defined in the album settings!');
     }
     // Check if there are some files in $_FILES
     if (!is_array($_FILES[$strName])) {
         $blnIsError = true;
         \Message::addError('No Files selected for the uploader.');
     }
     if ($blnIsError) {
         return array();
     }
     // Adapt $_FILES if files are loaded up by jumploader (java applet)
     if (!is_array($_FILES[$strName]['name'])) {
         $arrFile = array('name' => $_FILES[$strName]['name'], 'type' => $_FILES[$strName]['type'], 'tmp_name' => $_FILES[$strName]['tmp_name'], 'error' => $_FILES[$strName]['error'], 'size' => $_FILES[$strName]['size']);
         unset($_FILES);
         //rebuild $_FILES for the Contao FileUpload class
         $_FILES[$strName]['name'][0] = $arrFile['name'];
         $_FILES[$strName]['type'][0] = $arrFile['type'];
         $_FILES[$strName]['tmp_name'][0] = $arrFile['tmp_name'];
         $_FILES[$strName]['error'][0] = $arrFile['error'];
         $_FILES[$strName]['size'][0] = $arrFile['size'];
     }
     // Do not overwrite files of the same filename
     $intCount = count($_FILES[$strName]['name']);
     for ($i = 0; $i < $intCount; $i++) {
         if (strlen($_FILES[$strName]['name'][$i])) {
             // Generate unique filename
             $_FILES[$strName]['name'][$i] = basename(self::generateUniqueFilename($objUploadDir->path . '/' . $_FILES[$strName]['name'][$i]));
         }
     }
     // Resize image if feature is enabled
     if (\Input::post('img_resolution') > 1) {
         \Config::set('imageWidth', \Input::post('img_resolution'));
         \Config::set('jpgQuality', \Input::post('img_quality'));
     } else {
         \Config::set('maxImageWidth', 999999999);
     }
     // Call the Contao FileUpload class
     $objUpload = new \FileUpload();
     $objUpload->setName($strName);
     $arrUpload = $objUpload->uploadTo($objUploadDir->path);
     foreach ($arrUpload as $strFileSrc) {
         // Store file in tl_files
         \Dbafs::addResource($strFileSrc);
     }
     return $arrUpload;
 }
コード例 #7
0
ファイル: Upload.php プロジェクト: rburch/core
 /**
  * Initialize the FileUpload object
  * @param array
  */
 public function __construct($arrAttributes = null)
 {
     parent::__construct($arrAttributes);
     $this->objUploader = new \FileUpload();
     $this->objUploader->setName($this->strName);
 }
コード例 #8
0
 /**
  * Will save the image file as it is [If we only need to upload image without creating the thumbnails]
  *
  * @param file $file_element
  * @param string $module_name
  * @param integer $record_id
  * @param string $file_upload_path
  * @param string $filename
  */
 public function saveFile($file_element, $module_name = "", $record_id, $file_upload_path, $is_main_resize = false, $is_thumbnail = false)
 {
     $fileObj = new FileUpload();
     $fileObj->doInitialize($file_element);
     $filename = substr($file_element['name'], 0, strrpos($file_element['name'], '.'));
     $filename = $module_name . "_" . $record_id . $fileObj->getExtension();
     $fileObj->setName($filename);
     $fileObj->saveAs($file_upload_path);
     //to save the file physically on given location
     $savedImgPath = $fileObj->getFullPath();
     //This holds the full path of the file
     if ($is_main_resize) {
         $mainResize = PhpThumbFactory::create($savedImgPath);
         $mainResize->resize($this->mWidth, $this->mHeight);
         $mainResize->save($file_upload_path . $fileObj->getName());
     }
     if ($is_thumbnail) {
         $thumb = PhpThumbFactory::create($savedImgPath);
         //$thumb->adaptiveResize(80, 80);
         $thumb->resize($this->mThumbWidth, $this->mThumbHeight);
         $thumb->save($file_upload_path . "thumbnail/" . $fileObj->getName());
     }
     return $filename;
 }
コード例 #9
0
 private static function insertArt()
 {
     $sesion = new Session();
     if ($sesion->isLogged()) {
         $db = new DataBase();
         $manager = new ManageArt($db);
         $managerUser = new ManageUser($db);
         $email = Request::post("email");
         $title = Request::post("title");
         $usuario = $managerUser->get($email);
         $art = new Art();
         $art->setEmail($email);
         $art->setTitle($title);
         $art->setCdate(date('Y-m-d G:i:s'));
         $fecha = date('_Y_m_d_G_i_s');
         $photo = new FileUpload("image");
         if ($photo->getError() === false) {
             $art->setImage("./resources/art/" . $usuario->getAlias() . $fecha . ".jpg");
             $photo->setDestination("./resources/art/");
             $photo->setName($usuario->getAlias() . $fecha);
             $photo->upload();
         }
         $manager->insert($art);
         $db->close();
     }
     self::viewProfile();
 }