当前位置: 首页>>代码示例>>PHP>>正文


PHP FileUpload::uploadTo方法代码示例

本文整理汇总了PHP中FileUpload::uploadTo方法的典型用法代码示例。如果您正苦于以下问题:PHP FileUpload::uploadTo方法的具体用法?PHP FileUpload::uploadTo怎么用?PHP FileUpload::uploadTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileUpload的用法示例。


在下文中一共展示了FileUpload::uploadTo方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validator

 /**
  * Trim values
  * @param mixed
  * @return mixed
  */
 protected function validator($varInput)
 {
     $strUploadTo = 'system/tmp';
     // Specify the target folder in the DCA (eval)
     if (isset($this->arrConfiguration['uploadFolder'])) {
         $strUploadTo = $this->arrConfiguration['uploadFolder'];
     }
     $this->objUploader->uploadTo($strUploadTo);
 }
开发者ID:rburch,项目名称:core,代码行数:14,代码来源:Upload.php

示例2: importTable

    /**
     * Return a form to choose a CSV file and import it
     *
     * @param DataContainer $dc
     *
     * @return string
     */
    public function importTable(DataContainer $dc)
    {
        if (\Input::get('key') != 'table') {
            return '';
        }
        /** @var FileUpload $objUploader */
        $objUploader = new \FileUpload();
        // Import CSS
        if (\Input::post('FORM_SUBMIT') == 'tl_table_import') {
            $arrUploaded = $objUploader->uploadTo('system/tmp');
            if (empty($arrUploaded)) {
                \Message::addError($GLOBALS['TL_LANG']['ERR']['all_fields']);
                $this->reload();
            }
            $this->import('Database');
            $arrTable = array();
            foreach ($arrUploaded as $strCsvFile) {
                $objFile = new \File($strCsvFile);
                if ($objFile->extension != 'csv') {
                    \Message::addError(sprintf($GLOBALS['TL_LANG']['ERR']['filetype'], $objFile->extension));
                    continue;
                }
                // Get separator
                switch (\Input::post('separator')) {
                    case 'semicolon':
                        $strSeparator = ';';
                        break;
                    case 'tabulator':
                        $strSeparator = "\t";
                        break;
                    default:
                        $strSeparator = ',';
                        break;
                }
                $resFile = $objFile->handle;
                while (($arrRow = @fgetcsv($resFile, null, $strSeparator)) !== false) {
                    $arrTable[] = $arrRow;
                }
            }
            $objVersions = new \Versions($dc->table, \Input::get('id'));
            $objVersions->create();
            $this->Database->prepare("UPDATE " . $dc->table . " SET tableitems=? WHERE id=?")->execute(serialize($arrTable), \Input::get('id'));
            \System::setCookie('BE_PAGE_OFFSET', 0, 0);
            $this->redirect(str_replace('&key=table', '', \Environment::get('request')));
        }
        // Return form
        return '
<div id="tl_buttons">
<a href="' . ampersand(str_replace('&key=table', '', \Environment::get('request'))) . '" class="header_back" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a>
</div>
' . \Message::generate() . '
<form action="' . ampersand(\Environment::get('request'), true) . '" id="tl_table_import" class="tl_form" method="post" enctype="multipart/form-data">
<div class="tl_formbody_edit">
<input type="hidden" name="FORM_SUBMIT" value="tl_table_import">
<input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '">

<fieldset class="tl_tbox nolegend">
<div>
  <h3><label for="separator">' . $GLOBALS['TL_LANG']['MSC']['separator'][0] . '</label></h3>
  <select name="separator" id="separator" class="tl_select" onfocus="Backend.getScrollOffset()">
    <option value="comma">' . $GLOBALS['TL_LANG']['MSC']['comma'] . '</option>
    <option value="semicolon">' . $GLOBALS['TL_LANG']['MSC']['semicolon'] . '</option>
    <option value="tabulator">' . $GLOBALS['TL_LANG']['MSC']['tabulator'] . '</option>
  </select>' . ($GLOBALS['TL_LANG']['MSC']['separator'][1] != '' ? '
  <p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['MSC']['separator'][1] . '</p>' : '') . '
  <h3>' . $GLOBALS['TL_LANG']['MSC']['source'][0] . '</h3>' . $objUploader->generateMarkup() . (isset($GLOBALS['TL_LANG']['MSC']['source'][1]) ? '
  <p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['MSC']['source'][1] . '</p>' : '') . '
</div>
</fieldset>

</div>

<div class="tl_formbody_submit">

<div class="tl_submit_container">
  <button type="submit" name="save" id="save" class="tl_submit" accesskey="s">' . $GLOBALS['TL_LANG']['MSC']['tw_import'][0] . '</button>
</div>

</div>
</form>';
    }
开发者ID:qzminski,项目名称:contao-core-bundle,代码行数:88,代码来源:TableWizard.php

示例3: validateUpload

 /**
  * 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];
 }
开发者ID:Aziz-JH,项目名称:core,代码行数:44,代码来源:MediaManager.php

示例4: validateUpload

 /**
  * 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;
 }
开发者ID:kikmedia,项目名称:contao-fineuploader,代码行数:85,代码来源:FineUploaderBase.php

示例5: uploadTo

 /**
  * @inheritdoc
  */
 public function uploadTo($strTarget)
 {
     $this->target = $strTarget;
     $uploadTypes = $GLOBALS['TL_CONFIG']['uploadTypes'];
     $GLOBALS['TL_CONFIG']['uploadTypes'] = implode(',', $this->extensions);
     $filesizeLabel = $GLOBALS['TL_LANG']['ERR']['filesize'];
     $GLOBALS['TL_LANG']['ERR']['filesize'] = $GLOBALS['TL_LANG']['ERR']['maxFileSize'];
     $result = parent::uploadTo($strTarget);
     $GLOBALS['TL_CONFIG']['uploadTypes'] = $uploadTypes;
     $GLOBALS['TL_LANG']['ERR']['filesize'] = $filesizeLabel;
     return $result;
 }
开发者ID:codefog,项目名称:contao-haste,代码行数:15,代码来源:FileUpload.php

示例6: validateUpload

 /**
  * 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;
 }
开发者ID:revision6,项目名称:contao-avatar,代码行数:74,代码来源:AvatarWidgetBase.php

示例7: importStyleSheet

    /**
     * Return a form to choose an existing style sheet and import it
     *
     * @return string
     *
     * @throws \Exception
     */
    public function importStyleSheet()
    {
        if (\Input::get('key') != 'import') {
            return '';
        }
        /** @var FileUpload $objUploader */
        $objUploader = new \FileUpload();
        // Import CSS
        if (\Input::post('FORM_SUBMIT') == 'tl_style_sheet_import') {
            $arrUploaded = $objUploader->uploadTo('system/tmp');
            if (empty($arrUploaded)) {
                \Message::addError($GLOBALS['TL_LANG']['ERR']['all_fields']);
                $this->reload();
            }
            foreach ($arrUploaded as $strCssFile) {
                // Folders cannot be imported
                if (is_dir(TL_ROOT . '/' . $strCssFile)) {
                    \Message::addError(sprintf($GLOBALS['TL_LANG']['ERR']['importFolder'], basename($strCssFile)));
                    continue;
                }
                $objFile = new \File($strCssFile);
                // Check the file extension
                if ($objFile->extension != 'css') {
                    \Message::addError(sprintf($GLOBALS['TL_LANG']['ERR']['filetype'], $objFile->extension));
                    continue;
                }
                // Check the file name
                $strName = preg_replace('/\\.css$/i', '', basename($strCssFile));
                $strName = $this->checkStyleSheetName($strName);
                // Create the new style sheet
                $objStyleSheet = $this->Database->prepare("INSERT INTO tl_style_sheet (pid, tstamp, name, media) VALUES (?, ?, ?, ?)")->execute(\Input::get('id'), time(), $strName, array('all'));
                $insertId = $objStyleSheet->insertId;
                if (!is_numeric($insertId) || $insertId < 0) {
                    throw new \Exception('Invalid insert ID');
                }
                // Read the file and remove carriage returns
                $strFile = $objFile->getContent();
                $strFile = str_replace("\r", '', $strFile);
                $arrTokens = array();
                $strBuffer = '';
                $intSorting = 0;
                $strComment = '';
                $strCategory = '';
                $intLength = strlen($strFile);
                // Tokenize
                for ($i = 0; $i < $intLength; $i++) {
                    $char = $strFile[$i];
                    // Whitespace
                    if ($char == '' || $char == "\n" || $char == "\t") {
                        // Ignore
                    } elseif ($char == '/') {
                        if ($strFile[$i + 1] == '*') {
                            while ($i < $intLength) {
                                $strBuffer .= $strFile[$i++];
                                if ($strFile[$i] == '/' && $strFile[$i - 1] == '*') {
                                    $arrTokens[] = array('type' => 'comment', 'content' => $strBuffer . $strFile[$i]);
                                    $strBuffer = '';
                                    break;
                                }
                            }
                        }
                    } elseif ($char == '@') {
                        $intLevel = 0;
                        $strSelector = '';
                        while ($i < $intLength) {
                            $strBuffer .= $strFile[$i++];
                            if ($strFile[$i] == '{') {
                                if (++$intLevel == 1) {
                                    ++$i;
                                    $strSelector = $strBuffer;
                                    $strBuffer = '';
                                }
                            } elseif ($strFile[$i] == '}') {
                                if (--$intLevel == 0) {
                                    $arrTokens[] = array('type' => 'atblock', 'selector' => $strSelector, 'content' => $strBuffer);
                                    $strBuffer = '';
                                    break;
                                }
                            }
                        }
                    } else {
                        $strSelector = '';
                        while ($i < $intLength) {
                            $strBuffer .= $strFile[$i++];
                            if ($strFile[$i] == '{') {
                                ++$i;
                                $strSelector = $strBuffer;
                                $strBuffer = '';
                            } elseif ($strFile[$i] == '}') {
                                $arrTokens[] = array('type' => 'block', 'selector' => $strSelector, 'content' => $strBuffer);
                                $strBuffer = '';
                                break;
                            }
//.........这里部分代码省略.........
开发者ID:qzminski,项目名称:contao-core-bundle,代码行数:101,代码来源:StyleSheets.php

示例8: fileupload

 /**
  * 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;
 }
开发者ID:Aiod,项目名称:gallery_creator,代码行数:66,代码来源:GcHelpers.php


注:本文中的FileUpload::uploadTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。