Documentation TYPO3 par Ameos

file_upload.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00052 $BACK_PATH = '';
00053 require('init.php');
00054 require('template.php');
00055 $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
00056 require_once(PATH_t3lib.'class.t3lib_basicfilefunc.php');
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00077 class SC_file_upload {
00078 
00079                 // External, static:
00080         var $uploadNumber=10;
00081 
00082                 // Internal, static:
00083         var $doc;                       // Template object.
00084         var $basicff;           // Instance of "t3lib_basicFileFunctions"
00085         var $icon;                      // Will be set to the proper icon for the $target value.
00086         var $shortPath;         // Relative path to current found filemount
00087         var $title;                     // Name of the filemount
00088 
00089                 // Internal, static (GPVar):
00090         var $number;
00091         var $target;            // Set with the target path inputted in &target
00092         var $returnUrl;         // Return URL of list module.
00093 
00094                 // Internal, dynamic:
00095         var $content;           // Accumulating content
00096 
00097 
00103         function init() {
00104                 global $LANG,$BACK_PATH,$TYPO3_CONF_VARS;
00105 
00106                         // Initialize GPvars:
00107                 $this->number = t3lib_div::_GP('number');
00108                 $this->target = t3lib_div::_GP('target');
00109                 $this->returnUrl = t3lib_div::_GP('returnUrl');
00110 
00111                 if (empty($this->number))       {
00112                         $defaultFileUploads = $GLOBALS['BE_USER']->getTSConfigVal('options.defaultFileUploads');
00113                         if ($defaultFileUploads)        {
00114                                 $this->number = t3lib_div::intInRange($defaultFileUploads,1,$this->uploadNumber);
00115                         }
00116                 }
00117                         // Init basic-file-functions object:
00118                 $this->basicff = t3lib_div::makeInstance('t3lib_basicFileFunctions');
00119                 $this->basicff->init($GLOBALS['FILEMOUNTS'],$TYPO3_CONF_VARS['BE']['fileExtensions']);
00120 
00121                         // Cleaning and checking target
00122                 $this->target=$this->basicff->is_directory($this->target);              // Cleaning and checking target
00123                 $key=$this->basicff->checkPathAgainstMounts($this->target.'/');
00124                 if (!$this->target || !$key)    {
00125                         t3lib_BEfunc::typo3PrintError ('Parameter Error','Target was not a directory!','');
00126                         exit;
00127                 }
00128 
00129                         // Finding the icon
00130                 switch($GLOBALS['FILEMOUNTS'][$key]['type'])    {
00131                         case 'user':    $this->icon = 'gfx/i/_icon_ftp_user.gif';       break;
00132                         case 'group':   $this->icon = 'gfx/i/_icon_ftp_group.gif';      break;
00133                         default:                $this->icon = 'gfx/i/_icon_ftp.gif';    break;
00134                 }
00135 
00136                         // Relative path to filemount, $key:
00137                 $this->shortPath = substr($this->target,strlen($GLOBALS['FILEMOUNTS'][$key]['path']));
00138 
00139                         // Setting title:
00140                 $this->title = $GLOBALS['FILEMOUNTS'][$key]['name'].': '.$this->shortPath;
00141 
00142                         // Setting template object
00143                 $this->doc = t3lib_div::makeInstance('smallDoc');
00144                 $this->doc->docType = 'xhtml_trans';
00145                 $this->doc->backPath = $BACK_PATH;
00146                 $this->doc->form='<form action="tce_file.php" method="post" name="editform" enctype="'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'].'">';
00147 
00148                 if($GLOBALS['BE_USER']->jsConfirmation(1))      {
00149                         $confirm = ' && confirm('.$LANG->JScharCode($LANG->sL('LLL:EXT:lang/locallang_core.php:mess.redraw')).')';
00150                 } else {
00151                         $confirm = '';
00152                 }
00153                 $this->doc->JScode=$this->doc->wrapScriptTags('
00154                         var path = "'.$this->target.'";
00155 
00156                         function reload(a)      {       //
00157                                 if (!changed || (changed '.$confirm.')) {
00158                                         var params = "&target="+escape(path)+"&number="+a+"&returnUrl='.htmlspecialchars($this->returnUrl).'";
00159                                         window.location.href = "file_upload.php?"+params;
00160                                 }
00161                         }
00162                         function backToList()   {       //
00163                                 top.goToModule("file_list");
00164                         }
00165                         var changed = 0;
00166                 ');
00167         }
00168 
00174         function main() {
00175                 global $LANG;
00176 
00177                         // Make page header:
00178                 $this->content='';
00179                 $this->content.=$this->doc->startPage($LANG->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.pagetitle'));
00180                 $this->content.=$this->doc->header($LANG->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.pagetitle'));
00181                 $this->content.=$this->doc->spacer(5);
00182                 $this->content.=$this->doc->section('',$this->doc->getFileheader($this->title,$this->shortPath,$this->icon));
00183                 $this->content.=$this->doc->divider(5);
00184 
00185 
00186                         // Making the selector box for the number of concurrent uploads
00187                 $this->number = t3lib_div::intInRange($this->number,1,10);
00188                 $code='
00189                         <div id="c-select">
00190                                 <select name="number" onchange="reload(this.options[this.selectedIndex].value);">';
00191                 for ($a=1;$a<=$this->uploadNumber;$a++) {
00192                         $code.='
00193                                         <option value="'.$a.'"'.($this->number==$a?' selected="selected"':'').'>'.$a.' '.$LANG->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.files',1).'</option>';
00194                 }
00195                 $code.='
00196                                 </select>
00197                         </div>
00198                         ';
00199 
00200                         // Make checkbox for "overwrite"
00201                 $code.='
00202                         <div id="c-override">
00203                                 <input type="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="1" /> <label for="overwriteExistingFiles">'.$LANG->getLL('overwriteExistingFiles',1).'</label>
00204                         </div>
00205                         ';
00206 
00207                         // Produce the number of upload-fields needed:
00208                 $code.='
00209                         <div id="c-upload">
00210                 ';
00211                 for ($a=0;$a<$this->number;$a++)        {
00212                                 // Adding 'size="50" ' for the sake of Mozilla!
00213                         $code.='
00214                                 <input type="file" name="upload_'.$a.'"'.$this->doc->formWidth(35).' size="50" onclick="changed=1;" />
00215                                 <input type="hidden" name="file[upload]['.$a.'][target]" value="'.htmlspecialchars($this->target).'" />
00216                                 <input type="hidden" name="file[upload]['.$a.'][data]" value="'.$a.'" /><br />
00217                         ';
00218                 }
00219                 $code.='
00220                         </div>
00221                 ';
00222 
00223                         // Submit button:
00224                 $code.='
00225                         <div id="c-submit">
00226                                 <input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.submit',1).'" />
00227                                 <input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.cancel',1).'" onclick="backToList(); return false;" />
00228                                 <input type="hidden" name="redirect" value="'.htmlspecialchars($this->returnUrl).'" />
00229                         </div>
00230                 ';
00231 
00232                         // CSH:
00233                 $code.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_upload', $GLOBALS['BACK_PATH'],'<br/>');
00234 
00235                         // Add the HTML as a section:
00236                 $this->content.= $this->doc->section('',$code);
00237         }
00238 
00244         function printContent() {
00245                 $this->content.= $this->doc->endPage();
00246                 $this->content = $this->doc->insertStylesAndJS($this->content);
00247                 echo $this->content;
00248         }
00249 }
00250 
00251 // Include extension?
00252 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_upload.php'])   {
00253         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_upload.php']);
00254 }
00255 
00256 
00257 
00258 
00259 
00260 
00261 
00262 
00263 
00264 
00265 
00266 
00267 // Make instance:
00268 $SOBE = t3lib_div::makeInstance('SC_file_upload');
00269 $SOBE->init();
00270 $SOBE->main();
00271 $SOBE->printContent();
00272 ?>


Généré par TYPO3 Ameos avec  doxygen 1.4.6