Project

General

Profile

1 4 ryan
<?php
2 1400 FrankH
/**
3
 *
4
 * @category        admin
5
 * @package         admintools
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id$
14
 * @filesource		$HeadURL:  $
15
 * @lastmodified    $Date:  $
16
 *
17
 */
18 4 ryan
19
// Target location
20
if(!isset($_POST['target']) OR $_POST['target'] == '') {
21
	header("Location: index.php");
22 286 stefan
	exit(0);
23 4 ryan
} else {
24
	$target = $_POST['target'];
25
}
26
27
// Print admin header
28
require('../../config.php');
29 1041 Ruebenwurz
include_once('resize_img.php');
30
include_once('parameters.php');
31
32 4 ryan
require_once(WB_PATH.'/framework/class.admin.php');
33 1023 Ruebenwurz
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');	// Required to unzip file.
34 4 ryan
$admin = new admin('Media', 'media_upload');
35
36 1400 FrankH
if (!$admin->checkFTAN())
37
{
38 1425 Luisehahne
	$admin->print_error('UP5::'.$MESSAGE['GENERIC_SECURITY_ACCESS']);
39 1400 FrankH
	exit();
40
}
41
42 4 ryan
// Include the WB functions file
43
require_once(WB_PATH.'/framework/functions.php');
44
45
// Check to see if target contains ../
46 1425 Luisehahne
if (!check_media_path($target, false))
47
{
48
	$admin->print_error('TD5::'.$MESSAGE['MEDIA']['TARGET_DOT_DOT_SLASH']);
49 4 ryan
}
50
51
// Create relative path of the target location for the file
52
$relative = WB_PATH.$target.'/';
53 1102 ruud
$resizepath = str_replace(array('/',' '),'_',$target);
54 4 ryan
55
// Find out whether we should replace files or give an error
56
if($admin->get_post('overwrite') != '') {
57
	$overwrite = true;
58
} else {
59
	$overwrite = false;
60
}
61
62 61 stefan
// Get list of file types to which we're supposed to append 'txt'
63
$get_result=$database->query("SELECT value FROM ".TABLE_PREFIX."settings WHERE name='rename_files_on_upload' LIMIT 1");
64
$file_extension_string='';
65
if ($get_result->numRows()>0) {
66
	$fetch_result=$get_result->fetchRow();
67
	$file_extension_string=$fetch_result['value'];
68
}
69
$file_extensions=explode(",",$file_extension_string);
70
71
72 4 ryan
// Loop through the files
73
$good_uploads = 0;
74
for($count = 1; $count <= 10; $count++) {
75
	// If file was upload to tmp
76
	if(isset($_FILES["file$count"]['name'])) {
77
		// Remove bad characters
78
		$filename = media_filename($_FILES["file$count"]['name']);
79
		// Check if there is still a filename left
80
		if($filename != '') {
81 61 stefan
			// Check for potentially malicious files and append 'txt' to their name
82
			foreach($file_extensions as $file_ext) {
83
				$file_ext_len=strlen($file_ext);
84
				if (substr($filename,-$file_ext_len)==$file_ext) {
85
					$filename.='.txt';
86
				}
87
			}
88 4 ryan
			// Move to relative path (in media folder)
89
			if(file_exists($relative.$filename) AND $overwrite == true) {
90
				if(move_uploaded_file($_FILES["file$count"]['tmp_name'], $relative.$filename)) {
91
					$good_uploads++;
92
					// Chmod the uploaded file
93
					change_mode($relative.$filename, 'file');
94
				}
95
			} elseif(!file_exists($relative.$filename)) {
96
				if(move_uploaded_file($_FILES["file$count"]['tmp_name'], $relative.$filename)) {
97
					$good_uploads++;
98
					// Chmod the uploaded file
99
					change_mode($relative.$filename);
100
				}
101
			}
102 1041 Ruebenwurz
103
			if(file_exists($relative.$filename)) {
104
				if ($pathsettings[$resizepath]['width'] || $pathsettings[$resizepath]['height'] ) {
105
					$rimg=new RESIZEIMAGE($relative.$filename);
106
					$rimg->resize_limitwh($pathsettings[$resizepath]['width'],$pathsettings[$resizepath]['height'],$relative.$filename);
107
					$rimg->close();
108
				}
109
			}
110
111 1023 Ruebenwurz
			// store file name of first file for possible unzip action
112
			if ($count == 1) {
113
				$filename1 = $relative . $filename;
114
			}
115 4 ryan
		}
116
	}
117
}
118
119 1023 Ruebenwurz
// If the user chose to unzip the first file, unzip into the current folder
120
if (isset($_POST['unzip']) && isset($filename1) && file_exists($filename1) ) {
121
	$archive = new PclZip($filename1);
122
	$list = $archive->extract(PCLZIP_OPT_PATH, $relative);
123
	if($list == 0) {
124
		// error while trying to extract the archive (most likely wrong format)
125
		$admin->print_error('UNABLE TO UNZIP FILE' . $archive -> errorInfo(true));
126
	}
127 1407 FrankH
128
	// rename executable files!
129
	foreach ($list as $val) {
130
		$fn = $val['filename'];
131
		$fnp = pathinfo($fn);
132
		if (isset($fnp['extension'])) {
133
			$fext = $fnp['extension'];
134
			if (in_array($fext, $file_extensions)) {
135
				rename($fn, $fn.".txt");
136
			}
137
		}
138
	}
139 1023 Ruebenwurz
}
140
141 4 ryan
if($good_uploads == 1) {
142 1023 Ruebenwurz
	$admin->print_success($good_uploads.' '.$MESSAGE['MEDIA']['SINGLE_UPLOADED']);
143
	if (isset($_POST['delzip'])) {
144
		unlink($filename1);
145
	}
146 4 ryan
} else {
147 1023 Ruebenwurz
	$admin->print_success($good_uploads.' '.$MESSAGE['MEDIA']['UPLOADED']);
148 4 ryan
}
149
150
// Print admin
151
$admin->print_footer();
152
153 399 Ruebenwurz
?>