Quick Search:

View

Revision:

Diff

Diff from 978 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/tags/oscommerce-3.0a3/admin/file_manager.php

Annotated File View

hpdl
1
1 <?php
2 /*
mattice
151
3   $Id: file_manager.php 849 2006-08-29 20:23:24Z hpdl $
hpdl
1
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
hpdl
410
8   Copyright (c) 2006 osCommerce
hpdl
1
9
10   Released under the GNU General Public License
11 */
12
13   require('includes/application_top.php');
14
15   define('OSC_ADMIN_FILE_MANAGER_ROOT_PATH', realpath('../'));
16
hpdl
365
17   if (isset($_SESSION['fm_directory'])) {
18     $current_path = $_SESSION['fm_directory'];
hpdl
1
19   } else {
20     $current_path = OSC_ADMIN_FILE_MANAGER_ROOT_PATH;
hpdl
365
21     $_SESSION['fm_directory'] = $current_path;
hpdl
1
22   }
23
24   if (isset($_GET['directory'])) {
25     $current_path .= '/' . $_GET['directory'];
hpdl
365
26     $_SESSION['fm_directory'] = $current_path;
hpdl
1
27   } elseif (isset($_GET['goto'])) {
28     $current_path = OSC_ADMIN_FILE_MANAGER_ROOT_PATH . '/' . urldecode($_GET['goto']);
hpdl
365
29     $_SESSION['fm_directory'] = $current_path;
hpdl
1
30   }
31
32   $current_path = realpath($current_path);
33
34   if ( (substr($current_path, 0, strlen(OSC_ADMIN_FILE_MANAGER_ROOT_PATH)) != OSC_ADMIN_FILE_MANAGER_ROOT_PATH) || (is_dir($current_path) === false) ) {
35     $current_path = OSC_ADMIN_FILE_MANAGER_ROOT_PATH;
hpdl
365
36     $_SESSION['fm_directory'] = $current_path;
hpdl
1
37   }
38
39   $action = (isset($_GET['action']) ? $_GET['action'] : '');
40
41   if (!empty($action)) {
42     switch ($action) {
43       case 'reset':
hpdl
365
44         unset($_SESSION['fm_directory']);
hpdl
1
45
hpdl
758
46         osc_redirect(osc_href_link_admin(FILENAME_FILE_MANAGER));
hpdl
1
47         break;
48       case 'deleteconfirm':
49         if (isset($_GET['entry']) && !empty($_GET['entry'])) {
50           $target = $current_path . '/' . basename($_GET['entry']);
51
52           if (is_writeable($target)) {
hpdl
758
53             osc_remove($target);
hpdl
1
54           } else {
55             if (is_file($target)) {
56               $osC_MessageStack->add_session('header', sprintf(ERROR_FILE_NOT_WRITEABLE, $target), 'error');
57             } else {
58               $osC_MessageStack->add_session('header', sprintf(ERROR_DIRECTORY_NOT_WRITEABLE, $target), 'error');
59             }
60           }
61         }
62
hpdl
758
63         osc_redirect(osc_href_link_admin(FILENAME_FILE_MANAGER));
hpdl
1
64         break;
65       case 'new_directory':
66         if (isset($_POST['directory_name']) && !empty($_POST['directory_name'])) {
67           if (is_writeable($current_path)) {
68             $new_directory = $current_path . '/' . basename($_POST['directory_name']);
69
70             if (file_exists($new_directory) === false) {
71               if (mkdir($new_directory, 0777)) {
hpdl
758
72                 osc_redirect(osc_href_link_admin(FILENAME_FILE_MANAGER, 'entry=' . urlencode(basename($_POST['directory_name']))));
hpdl
1
73               }
74             } else {
75               $osC_MessageStack->add('header', sprintf(ERROR_DIRECTORY_EXISTS, $new_directory), 'error');
76             }
77           } else {
78             $osC_MessageStack->add_session('header', sprintf(ERROR_DIRECTORY_NOT_WRITEABLE, $current_path), 'error');
79           }
80         }
81
hpdl
758
82         osc_redirect(osc_href_link_admin(FILENAME_FILE_MANAGER));
hpdl
1
83         break;
84       case 'save':
85         if ( (isset($_GET['entry']) && !empty($_GET['entry'])) || (isset($_POST['filename']) && !empty($_POST['filename'])) ) {
86           if (isset($_GET['entry']) && !empty($_GET['entry'])) {
87             $filename = basename($_GET['entry']);
88           } elseif (isset($_POST['filename']) && !empty($_POST['filename'])) {
89             $filename = basename($_POST['filename']);
90           }
91
92           if ($fp = fopen($current_path . '/' . $filename, 'w+')) {
93             fputs($fp, $_POST['contents']);
94             fclose($fp);
95           }
96
hpdl
758
97           osc_redirect(osc_href_link_admin(FILENAME_FILE_MANAGER, 'entry=' . $filename));
hpdl
1
98         }
99
hpdl
758
100         osc_redirect(osc_href_link_admin(FILENAME_FILE_MANAGER));
hpdl
1
101         break;
102       case 'processuploads':
103         if (is_writeable($current_path)) {
104           for ($i=0; $i<10; $i++) {
hpdl
849
105             $file = new upload('file_' . $i, $current_path);
106
107             if ($file->exists()) {
108               $file->parse();
109               $file->save();
110             }
hpdl
1
111           }
112         } else {
113           $osC_MessageStack->add_session('header', sprintf(ERROR_DIRECTORY_NOT_WRITEABLE, $current_path), 'error');
114         }
115
hpdl
758
116         osc_redirect(osc_href_link_admin(FILENAME_FILE_MANAGER));
hpdl
1
117         break;
118       case 'download':
119         if (isset($_GET['entry']) && !empty($_GET['entry'])) {
120           $target = $current_path . '/' . basename($_GET['entry']);
121
122           if (file_exists($target)) {
123             header('Content-type: application/x-octet-stream');
124             header('Content-disposition: attachment; filename=' . urldecode(basename($_GET['entry'])));
125
126             readfile($target);
127             exit;
128           }
129         }
130         break;
131     }
132   }
133
134   $goto_array = array(array('id' => '', 'text' => '--TOP--'));
135
136   if ($current_path != OSC_ADMIN_FILE_MANAGER_ROOT_PATH) {
137     $path_array = explode('/', substr($current_path, strlen(OSC_ADMIN_FILE_MANAGER_ROOT_PATH)+1));
138
139     foreach ($path_array as $value) {
140       if (sizeof($goto_array) < 2) {
141         $goto_array[] = array('id' => $value, 'text' => $value);
142       } else {
143         $parent = end($goto_array);
144         $goto_array[] = array('id' => $parent['id'] . '/' . $value, 'text' => $parent['id'] . '/' . $value);
145       }
146     }
147   }
148
149   switch ($action) {
150     case 'fmEdit': $page_contents = 'file_manager_edit.php'; break;
151     default: $page_contents = 'file_manager.php';
152   }
153
154   require('templates/default.php');
155
156   require('includes/application_bottom.php');
157 ?>