Project

General

Profile

1 4 ryan
<?php
2
3
// $Id: upload.php,v 1.11 2005/04/25 11:53:12 rdjurovich Exp $
4
5
/*
6
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2005, Ryan Djurovich
9
10
 Website Baker is free software; you can redistribute it and/or modify
11
 it under the terms of the GNU General Public License as published by
12
 the Free Software Foundation; either version 2 of the License, or
13
 (at your option) any later version.
14
15
 Website Baker is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU General Public License for more details.
19
20
 You should have received a copy of the GNU General Public License
21
 along with Website Baker; if not, write to the Free Software
22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
24
*/
25
26
// Target location
27
if(!isset($_POST['target']) OR $_POST['target'] == '') {
28
	header("Location: index.php");
29
} else {
30
	$target = $_POST['target'];
31
}
32
33
// Print admin header
34
require('../../config.php');
35
require_once(WB_PATH.'/framework/class.admin.php');
36
$admin = new admin('Media', 'media_upload');
37
38
// Include the WB functions file
39
require_once(WB_PATH.'/framework/functions.php');
40
41
// Check to see if target contains ../
42
if(strstr($target, '../')) {
43
	$admin->print_error($MESSAGE['MEDIA']['TARGET_DOT_DOT_SLASH']);
44
}
45
46
// Create relative path of the target location for the file
47
$relative = WB_PATH.$target.'/';
48
49
// Find out whether we should replace files or give an error
50
if($admin->get_post('overwrite') != '') {
51
	$overwrite = true;
52
} else {
53
	$overwrite = false;
54
}
55
56
// Loop through the files
57
$good_uploads = 0;
58
for($count = 1; $count <= 10; $count++) {
59
	// If file was upload to tmp
60
	if(isset($_FILES["file$count"]['name'])) {
61
		// Remove bad characters
62
		$filename = media_filename($_FILES["file$count"]['name']);
63
		// Check if there is still a filename left
64
		if($filename != '') {
65
			// Move to relative path (in media folder)
66
			if(file_exists($relative.$filename) AND $overwrite == true) {
67
				if(move_uploaded_file($_FILES["file$count"]['tmp_name'], $relative.$filename)) {
68
					$good_uploads++;
69
					// Chmod the uploaded file
70
					change_mode($relative.$filename, 'file');
71
				}
72
			} elseif(!file_exists($relative.$filename)) {
73
				if(move_uploaded_file($_FILES["file$count"]['tmp_name'], $relative.$filename)) {
74
					$good_uploads++;
75
					// Chmod the uploaded file
76
					change_mode($relative.$filename);
77
				}
78
			}
79
		}
80
	}
81
}
82
83
if($good_uploads == 1) {
84
	$admin->print_success($good_uploads.$MESSAGE['MEDIA']['SINGLE_UPLOADED']);
85
} else {
86
	$admin->print_success($good_uploads.$MESSAGE['MEDIA']['UPLOADED']);
87
}
88
89
// Print admin
90
$admin->print_footer();
91
92
?>