2 /***************************************************************
5 * (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * Web>File: Upload of files
31 * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
33 * @author Kasper Skaarhoj <kasper@typo3.com>
36 * [CLASS/FUNCTION INDEX of SCRIPT]
40 * 78: class SC_file_upload
41 * 103: function init()
42 * 161: function main()
43 * 230: function printContent()
46 * (This index is automatically created/updated by the extension "extdeveval")
54 require ('template.php');
55 include ('sysext/lang/locallang_misc.php');
56 require_once (PATH_t3lib
.'class.t3lib_basicfilefunc.php');
72 * Script Class for display up to 10 upload fields
74 * @author Kasper Skaarhoj <kasper@typo3.com>
78 class SC_file_upload
{
84 var $doc; // Template object.
85 var $basicff; // Instance of "t3lib_basicFileFunctions"
86 var $icon; // Will be set to the proper icon for the $target value.
87 var $shortPath; // Relative path to current found filemount
88 var $title; // Name of the filemount
90 // Internal, static (GPVar):
92 var $target; // Set with the target path inputted in &target
95 var $content; // Accumulating content
99 * Constructor for initializing the class
104 global $LANG,$BACK_PATH,$TYPO3_CONF_VARS;
106 // Initialize GPvars:
107 $this->number
= t3lib_div
::_GP('number');
108 $this->target
= t3lib_div
::_GP('target');
110 // Init basic-file-functions object:
111 $this->basicff
= t3lib_div
::makeInstance('t3lib_basicFileFunctions');
112 $this->basicff
->init($GLOBALS['FILEMOUNTS'],$TYPO3_CONF_VARS['BE']['fileExtensions']);
114 // Cleaning and checking target
115 $this->target
=$this->basicff
->is_directory($this->target
); // Cleaning and checking target
116 $key=$this->basicff
->checkPathAgainstMounts($this->target
.'/');
117 if (!$this->target ||
!$key) {
118 t3lib_BEfunc
::typo3PrintError ('Parameter Error','Target was not a directory!','');
123 switch($GLOBALS['FILEMOUNTS'][$key]['type']) {
124 case 'user': $this->icon
= 'gfx/i/_icon_ftp_user.gif'; break;
125 case 'group': $this->icon
= 'gfx/i/_icon_ftp_group.gif'; break;
126 default: $this->icon
= 'gfx/i/_icon_ftp.gif'; break;
129 // Relative path to filemount, $key:
130 $this->shortPath
= substr($this->target
,strlen($GLOBALS['FILEMOUNTS'][$key]['path']));
133 $this->title
= $GLOBALS['FILEMOUNTS'][$key]['name'].': '.$this->shortPath
;
135 // Setting template object
136 $this->doc
= t3lib_div
::makeInstance('smallDoc');
137 $this->doc
->docType
= 'xhtml_trans';
138 $this->doc
->backPath
= $BACK_PATH;
139 $this->doc
->form
='<form action="tce_file.php" method="post" name="editform" enctype="'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'].'">';
140 $this->doc
->JScode
=$this->doc
->wrapScriptTags('
141 var path = "'.$this->target
.'";
143 function reload(a) { //
144 if (!changed || (changed && confirm('.$LANG->JScharCode($LANG->sL('LLL:EXT:lang/locallang_core.php:mess.redraw')).'))) {
145 var params = "&target="+escape(path)+"&number="+a;
146 document.location = "file_upload.php?"+params;
149 function backToList() { //
150 top.goToModule("file_list");
157 * Main function, rendering the upload file form fields
166 $this->content
.=$this->doc
->startPage($LANG->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.pagetitle'));
167 $this->content
.=$this->doc
->header($LANG->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.pagetitle'));
168 $this->content
.=$this->doc
->spacer(5);
169 $this->content
.=$this->doc
->section('',$this->doc
->getFileheader($this->title
,$this->shortPath
,$this->icon
));
170 $this->content
.=$this->doc
->divider(5);
173 // Making the selector box for the number of concurrent uploads
174 $this->number
= t3lib_div
::intInRange($this->number
,1,10);
177 <select name="number" onchange="reload(this.options[this.selectedIndex].value);">';
178 for ($a=1;$a<=$this->uploadNumber
;$a++
) {
180 <option value="'.$a.'"'.($this->number
==$a?
' selected="selected"':'').'>'.$a.' '.$LANG->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.files',1).'</option>';
187 // Make checkbox for "overwrite"
189 <div id="c-override">
190 <input type="checkbox" name="overwriteExistingFiles" value="1" /> '.$LANG->getLL('overwriteExistingFiles',1).'
194 // Produce the number of upload-fields needed:
198 for ($a=0;$a<$this->number
;$a++
) {
199 // Adding 'size="50" ' for the sake of Mozilla!
201 <input type="file" name="upload_'.$a.'"'.$this->doc
->formWidth(35).' size="50" onclick="changed=1;" />
202 <input type="hidden" name="file[upload]['.$a.'][target]" value="'.htmlspecialchars($this->target
).'" />
203 <input type="hidden" name="file[upload]['.$a.'][data]" value="'.$a.'" /><br />
213 <input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:file_upload.php.submit',1).'" />
214 <input type="submit" value="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.cancel',1).'" onclick="backToList(); return false;" />
218 // Add the HTML as a section:
219 $this->content
.= $this->doc
->section('',$code);
222 $this->content
.= $this->doc
->endPage();
226 * Outputting the accumulated content to screen
230 function printContent() {
236 // Include extension?
237 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/file_upload.php']) {
238 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/file_upload.php']);
253 $SOBE = t3lib_div
::makeInstance('SC_file_upload');
256 $SOBE->printContent();