file_upload.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2008 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 ***************************************************************/
00027 /**
00028  * Web>File: Upload of files
00029  *
00030  * $Id: file_upload.php 4567 2008-12-18 18:10:00Z dmitry $
00031  * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
00032  *
00033  * @author  Kasper Skaarhoj <kasperYYYY@typo3.com>
00034  */
00035 /**
00036  * [CLASS/FUNCTION INDEX of SCRIPT]
00037  *
00038  *
00039  *
00040  *   77: class SC_file_upload
00041  *  103:     function init()
00042  *  171:     function main()
00043  *  241:     function printContent()
00044  *
00045  * TOTAL FUNCTIONS: 3
00046  * (This index is automatically created/updated by the extension "extdeveval")
00047  *
00048  */
00049 
00050 
00051 
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 require_once(PATH_t3lib.'class.t3lib_parsehtml.php');
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00070 /**
00071  * Script Class for display up to 10 upload fields
00072  *
00073  * @author  Kasper Skaarhoj <kasperYYYY@typo3.com>
00074  * @package TYPO3
00075  * @subpackage core
00076  */
00077 class SC_file_upload {
00078 
00079         // External, static:
00080     var $uploadNumber=10;
00081 
00082         // Internal, static:
00083     /**
00084      * Document template object
00085      *
00086      * @var smallDoc
00087      */
00088     var $doc;
00089 
00090     /**
00091      * File processing object
00092      *
00093      * @var t3lib_basicFileFunctions
00094      */
00095     var $basicff;
00096     var $icon;          // Will be set to the proper icon for the $target value.
00097     var $shortPath;     // Relative path to current found filemount
00098     var $title;         // Name of the filemount
00099 
00100     /**
00101      * Charset processing object
00102      *
00103      * @var t3lib_cs
00104      */
00105     protected $charsetConversion;
00106 
00107         // Internal, static (GPVar):
00108     var $number;
00109     var $target;        // Set with the target path inputted in &target
00110     var $returnUrl;     // Return URL of list module.
00111 
00112         // Internal, dynamic:
00113     var $content;       // Accumulating content
00114 
00115 
00116     /**
00117      * Constructor for initializing the class
00118      *
00119      * @return  void
00120      */
00121     function init() {
00122         global $LANG,$BACK_PATH,$TYPO3_CONF_VARS;
00123 
00124             // Initialize GPvars:
00125         $this->number = t3lib_div::_GP('number');
00126         $this->target = t3lib_div::_GP('target');
00127         $this->returnUrl = t3lib_div::_GP('returnUrl');
00128         $this->returnUrl = $this->returnUrl ? $this->returnUrl : t3lib_div::getIndpEnv('TYPO3_SITE_URL').TYPO3_mainDir.'file_list.php?id='.rawurlencode($this->target);
00129 
00130         if (empty($this->number))   {
00131             $defaultFileUploads = $GLOBALS['BE_USER']->getTSConfigVal('options.defaultFileUploads');
00132             if ($defaultFileUploads)    {
00133                 $this->number = t3lib_div::intInRange($defaultFileUploads,1,$this->uploadNumber);
00134             }
00135         }
00136             // Init basic-file-functions object:
00137         $this->basicff = t3lib_div::makeInstance('t3lib_basicFileFunctions');
00138         $this->basicff->init($GLOBALS['FILEMOUNTS'],$TYPO3_CONF_VARS['BE']['fileExtensions']);
00139 
00140             // Init basic-charset-functions object:
00141         $this->charsetConversion = t3lib_div::makeInstance('t3lib_cs');
00142 
00143             // Cleaning and checking target
00144         $this->target = $this->charsetConversion->conv($this->target, 'utf-8', $GLOBALS['LANG']->charSet);
00145         $this->target = $this->basicff->is_directory($this->target);
00146         $key=$this->basicff->checkPathAgainstMounts($this->target.'/');
00147         if (!$this->target || !$key)    {
00148             t3lib_BEfunc::typo3PrintError ($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:paramError', true), $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.xml:targetNoDir', true), '');
00149             exit;
00150         }
00151 
00152             // Finding the icon
00153         switch($GLOBALS['FILEMOUNTS'][$key]['type'])    {
00154             case 'user':    $this->icon = 'gfx/i/_icon_ftp_user.gif';   break;
00155             case 'group':   $this->icon = 'gfx/i/_icon_ftp_group.gif';  break;
00156             default:        $this->icon = 'gfx/i/_icon_ftp.gif';    break;
00157         }
00158 
00159         $this->icon = '<img'.t3lib_iconWorks::skinImg($this->backPath,$this->icon,'width="18" height="16"').' title="" alt="" />';
00160 
00161             // Relative path to filemount, $key:
00162         $this->shortPath = substr($this->target,strlen($GLOBALS['FILEMOUNTS'][$key]['path']));
00163 
00164             // Setting title:
00165         $this->title = $this->icon.$GLOBALS['FILEMOUNTS'][$key]['name'].': '.$this->shortPath;
00166 
00167             // Setting template object
00168         $this->doc = t3lib_div::makeInstance('template');
00169         $this->doc->setModuleTemplate('templates/file_upload.html');
00170         $this->doc->backPath = $BACK_PATH;
00171 
00172         if($GLOBALS['BE_USER']->jsConfirmation(1))  {
00173             $confirm = ' && confirm('.$LANG->JScharCode($LANG->sL('LLL:EXT:lang/locallang_core.php:mess.redraw')).')';
00174         } else {
00175             $confirm = '';
00176         }
00177         $this->doc->JScode=$this->doc->wrapScriptTags('
00178             var path = "'.$this->target.'";
00179 
00180             function reload(a)  {   //
00181                 if (!changed || (changed '.$confirm.')) {
00182                     var params = "&target="+encodeURIComponent(path)+"&number="+a+"&returnUrl='
00183                             . urlencode($this->charsetConversion->conv($this->returnUrl, $GLOBALS['LANG']->charSet, 'utf-8'))
00184                             . '";
00185                     window.location.href = "file_upload.php?"+params;
00186                 }
00187             }
00188             function backToList()   {   //
00189                 top.goToModule("file_list");
00190             }
00191             var changed = 0;
00192         ');
00193     }
00194 
00195     /**
00196      * Main function, rendering the upload file form fields
00197      *
00198      * @return  void
00199      */
00200     function main() {
00201         global $LANG;
00202 
00203             // Make page header:
00204         $this->content = $this->doc->startPage($LANG->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.pagetitle'));
00205 
00206         $pageContent.=$this->doc->header($LANG->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.pagetitle'));
00207         $pageContent.=$this->doc->spacer(5);
00208         $pageContent.=$this->doc->divider(5);
00209 
00210 
00211         $code = '<form action="tce_file.php" method="post" name="editform" enctype="'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'].'">';
00212             // Making the selector box for the number of concurrent uploads
00213         $this->number = t3lib_div::intInRange($this->number,1,10);
00214         $code .= '
00215             <div id="c-select">
00216                 <label for="number-of-uploads">' .
00217                 $LANG->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.number_of_files') .
00218                 '</label>
00219                 <select name="number" id="number-of-uploads" onchange="reload(this.options[this.selectedIndex].value);">';
00220         for ($a=1;$a<=$this->uploadNumber;$a++) {
00221             $code.='<option value="' . $a . '"' .
00222                         ($this->number == $a ? ' selected="selected"' : '' ) .
00223                         '>' . $a . '</option>';
00224         }
00225         $code.='
00226                 </select>
00227             </div>
00228             ';
00229 
00230             // Make checkbox for "overwrite"
00231         $code.='
00232             <div id="c-override">
00233                 <input type="checkbox" class="checkbox" name="overwriteExistingFiles" id="overwriteExistingFiles" value="1" /> <label for="overwriteExistingFiles">'.$LANG->getLL('overwriteExistingFiles',1).'</label>
00234             </div>
00235             ';
00236 
00237             // Produce the number of upload-fields needed:
00238         $code.='
00239             <div id="c-upload">
00240         ';
00241         for ($a=0;$a<$this->number;$a++)    {
00242                 // Adding 'size="50" ' for the sake of Mozilla!
00243             $code.='
00244                 <input type="file" name="upload_'.$a.'"'.$this->doc->formWidth(35).' size="50" onclick="changed=1;" />
00245                 <input type="hidden" name="file[upload]['.$a.'][target]" value="'.htmlspecialchars($this->target).'" />
00246                 <input type="hidden" name="file[upload]['.$a.'][data]" value="'.$a.'" /><br />
00247             ';
00248         }
00249         $code.='
00250             </div>
00251         ';
00252 
00253             // Submit button:
00254         $code.='
00255             <div id="c-submit">
00256                 <input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.submit',1).'" />
00257                 <input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.cancel',1).'" onclick="backToList(); return false;" />
00258                 <input type="hidden" name="redirect" value="'.htmlspecialchars($this->returnUrl).'" />
00259             </div>
00260         ';
00261 
00262             // Add the HTML as a section:
00263         $pageContent.= $this->doc->section('',$code);
00264 
00265 
00266             // Header Buttons
00267         $docHeaderButtons = array(
00268             'csh' => t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'file_upload', $GLOBALS['BACK_PATH'])
00269         );
00270 
00271         $markerArray = array(
00272             'CSH' => $docHeaderButtons['csh'],
00273             'FUNC_MENU' => t3lib_BEfunc::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']),
00274             'CONTENT' => $pageContent,
00275             'PATH' => $this->title,
00276         );
00277 
00278         $this->content.= $this->doc->moduleBody(array(), $docHeaderButtons, $markerArray);
00279         $this->content.= $this->doc->endPage();
00280         $this->content = $this->doc->insertStylesAndJS($this->content);
00281     }
00282 
00283     /**
00284      * Outputting the accumulated content to screen
00285      *
00286      * @return  void
00287      */
00288     function printContent() {
00289         echo $this->content;
00290     }
00291 }
00292 
00293 
00294 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_upload.php'])   {
00295     include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/file_upload.php']);
00296 }
00297 
00298 
00299 
00300 // Make instance:
00301 $SOBE = t3lib_div::makeInstance('SC_file_upload');
00302 $SOBE->init();
00303 $SOBE->main();
00304 $SOBE->printContent();
00305 
00306 ?>

Generated on Sat Jan 3 04:23:29 2009 for TYPO3 API by  doxygen 1.4.7