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) && $GLOBALS['BE_USER']->getTSConfig('options.defaultFileUploads'))     {
00112                         $this->number = t3lib_div::intInRange($GLOBALS['BE_USER']->getTSConfig('options.defaultFileUploads'),1,$this->uploadNumber);
00113                 }
00114                         // Init basic-file-functions object:
00115                 $this->basicff = t3lib_div::makeInstance('t3lib_basicFileFunctions');
00116                 $this->basicff->init($GLOBALS['FILEMOUNTS'],$TYPO3_CONF_VARS['BE']['fileExtensions']);
00117 
00118                         // Cleaning and checking target
00119                 $this->target=$this->basicff->is_directory($this->target);              // Cleaning and checking target
00120                 $key=$this->basicff->checkPathAgainstMounts($this->target.'/');
00121                 if (!$this->target || !$key)    {
00122                         t3lib_BEfunc::typo3PrintError ('Parameter Error','Target was not a directory!','');
00123                         exit;
00124                 }
00125 
00126                         // Finding the icon
00127                 switch($GLOBALS['FILEMOUNTS'][$key]['type'])    {
00128                         case 'user':    $this->icon = 'gfx/i/_icon_ftp_user.gif';       break;
00129                         case 'group':   $this->icon = 'gfx/i/_icon_ftp_group.gif';      break;
00130                         default:                $this->icon = 'gfx/i/_icon_ftp.gif';    break;
00131                 }
00132 
00133                         // Relative path to filemount, $key:
00134                 $this->shortPath = substr($this->target,strlen($GLOBALS['FILEMOUNTS'][$key]['path']));
00135 
00136                         // Setting title:
00137                 $this->title = $GLOBALS['FILEMOUNTS'][$key]['name'].': '.$this->shortPath;
00138 
00139                         // Setting template object
00140                 $this->doc = t3lib_div::makeInstance('smallDoc');
00141                 $this->doc->docType = 'xhtml_trans';
00142                 $this->doc->backPath = $BACK_PATH;
00143                 $this->doc->form='<form action="tce_file.php" method="post" name="editform" enctype="'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'].'">';
00144 
00145                 if($GLOBALS['BE_USER']->jsConfirmation(1))      {
00146                         $confirm = ' && confirm('.$LANG->JScharCode($LANG->sL('LLL:EXT:lang/locallang_core.php:mess.redraw')).')';
00147                 } else {
00148                         $confirm = '';
00149                 }
00150                 $this->doc->JScode=$this->doc->wrapScriptTags('
00151                         var path = "'.$this->target.'";
00152 
00153                         function reload(a)      {       //
00154                                 if (!changed || (changed '.$confirm.')) {
00155                                         var params = "&target="+escape(path)+"&number="+a+"&returnUrl='.htmlspecialchars($this->returnUrl).'";
00156                                         window.location.href = "file_upload.php?"+params;
00157                                 }
00158                         }
00159                         function backToList()   {       //
00160                                 top.goToModule("file_list");
00161                         }
00162                         var changed = 0;
00163                 ');
00164         }
00165 
00171         function main() {
00172                 global $LANG;
00173 
00174                         // Make page header:
00175                 $this->content='';
00176                 $this->content.=$this->doc->startPage($LANG->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.pagetitle'));
00177                 $this->content.=$this->doc->header($LANG->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.pagetitle'));
00178                 $this->content.=$this->doc->spacer(5);
00179                 $this->content.=$this->doc->section('',$this->doc->getFileheader($this->title,$this->shortPath,$this->icon));
00180                 $this->content.=$this->doc->divider(5);
00181 
00182 
00183                         // Making the selector box for the number of concurrent uploads
00184                 $this->number = t3lib_div::intInRange($this->number,1,10);
00185                 $code='
00186                         <div id="c-select">
00187                                 <select name="number" onchange="reload(this.options[this.selectedIndex].value);">';
00188                 for ($a=1;$a<=$this->uploadNumber;$a++) {
00189                         $code.='
00190                                         <option value="'.$a.'"'.($this->number==$a?' selected="selected"':'').'>'.$a.' '.$LANG->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.files',1).'</option>';
00191                 }
00192                 $code.='
00193                                 </select>
00194                         </div>
00195                         ';
00196 
00197                         // Make checkbox for "overwrite"
00198                 $code.='
00199                         <div id="c-override">
00200                                 <input type="checkbox" name="overwriteExistingFiles" value="1" /> '.$LANG->getLL('overwriteExistingFiles',1).'
00201                         </div>
00202                         ';
00203 
00204                         // Produce the number of upload-fields needed:
00205                 $code.='
00206                         <div id="c-upload">
00207                 ';
00208                 for ($a=0;$a<$this->number;$a++)        {
00209                                 // Adding 'size="50" ' for the sake of Mozilla!
00210                         $code.='
00211                                 <input type="file" name="upload_'.$a.'"'.$this->doc->formWidth(35).' size="50" onclick="changed=1;" />
00212                                 <input type="hidden" name="file[upload]['.$a.'][target]" value="'.htmlspecialchars($this->target).'" />
00213                                 <input type="hidden" name="file[upload]['.$a.'][data]" value="'.$a.'" /><br />
00214                         ';
00215                 }
00216                 $code.='
00217                         </div>
00218                 ';
00219 
00220                         // Submit button:
00221                 $code.='
00222                         <div id="c-submit">
00223                                 <input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.submit',1).'" />
00224                                 <input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.cancel',1).'" onclick="backToList(); return false;" />
00225                                 <input type="hidden" name="redirect" value="'.htmlspecialchars($this->returnUrl).'" />
00226                         </div>
00227                 ';
00228 
00229                         // CSH:
00230                 $code.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_upload', $GLOBALS['BACK_PATH'],'<br/>');
00231 
00232                         // Add the HTML as a section:
00233                 $this->content.= $this->doc->section('',$code);
00234         }
00235 
00241         function printContent() {
00242                 $this->content.= $this->doc->endPage();
00243                 $this->content = $this->doc->insertStylesAndJS($this->content);
00244                 echo $this->content;
00245         }
00246 }
00247 
00248 // Include extension?
00249 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_upload.php'])   {
00250         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_upload.php']);
00251 }
00252 
00253 
00254 
00255 
00256 
00257 
00258 
00259 
00260 
00261 
00262 
00263 
00264 // Make instance:
00265 $SOBE = t3lib_div::makeInstance('SC_file_upload');
00266 $SOBE->init();
00267 $SOBE->main();
00268 $SOBE->printContent();
00269 ?>


Généré par Le spécialiste TYPO3 avec  doxygen 1.4.6