source: extensions/upload_form/upload.php @ 4792

Revision 4789, 4.7 KB checked in by plg, 10 years ago (diff)

feature 1405 added: explicit errors when the "upload" directory is missing or
not writable.

Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2010      Pierrick LE GALL             http://piwigo.org |
6// +-----------------------------------------------------------------------+
7// | This program is free software; you can redistribute it and/or modify  |
8// | it under the terms of the GNU General Public License as published by  |
9// | the Free Software Foundation                                          |
10// |                                                                       |
11// | This program is distributed in the hope that it will be useful, but   |
12// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
13// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
14// | General Public License for more details.                              |
15// |                                                                       |
16// | You should have received a copy of the GNU General Public License     |
17// | along with this program; if not, write to the Free Software           |
18// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
19// | USA.                                                                  |
20// +-----------------------------------------------------------------------+
21
22if( !defined("PHPWG_ROOT_PATH") )
23{
24  die ("Hacking attempt!");
25}
26
27include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
28include_once(UPLOAD_FORM_PATH.'include/functions_upload.inc.php');
29load_language('plugin.lang', UPLOAD_FORM_PATH);
30
31$admin_base_url = get_root_url().'admin.php?page=plugin&section=upload_form%2Fupload.php';
32
33// +-----------------------------------------------------------------------+
34// | Check Access and exit when user status is not ok                      |
35// +-----------------------------------------------------------------------+
36check_status(ACCESS_ADMINISTRATOR);
37
38// +-----------------------------------------------------------------------+
39// |                               functions                               |
40// +-----------------------------------------------------------------------+
41
42if (isset($_POST['submit_upload']))
43{
44  // echo '<pre>'; print_r($_FILES); echo '</pre>'; exit();
45 
46  $starttime = get_moment();
47 
48  foreach ($_FILES['image_upload']['error'] as $idx => $error)
49  {
50    if (UPLOAD_ERR_OK == $error)
51    {
52      $source_filepath = $_FILES['image_upload']['tmp_name'][$idx];
53      $original_filename = $_FILES['image_upload']['name'][$idx];
54      add_uploaded_file($source_filepath, $original_filename, array($_POST['category']));
55    }
56  }
57 
58  $endtime = get_moment();
59  $elapsed = ($endtime - $starttime) * 1000;
60  // printf('%.2f ms', $elapsed);
61}
62
63// +-----------------------------------------------------------------------+
64// |                             template init                             |
65// +-----------------------------------------------------------------------+
66
67$template->set_filenames(
68  array(
69    'plugin_admin_content' => dirname(__FILE__).'/upload.tpl'
70    )
71  );
72
73$template->assign(
74    array(
75      'F_ADD_ACTION'=> $admin_base_url,
76      'plugin_path' => UPLOAD_FORM_PATH,
77    )
78  );
79
80$query = '
81SELECT id,name,uppercats,global_rank
82  FROM '.CATEGORIES_TABLE.'
83;';
84
85display_select_cat_wrapper(
86  $query,
87  array(),
88  'category_options'
89  );
90
91// +-----------------------------------------------------------------------+
92// |                             setup errors                              |
93// +-----------------------------------------------------------------------+
94
95$setup_errors = array();
96
97$upload_base_dir = 'upload';
98$upload_dir = PHPWG_ROOT_PATH.$upload_base_dir;
99
100if (!is_dir($upload_dir))
101{
102  if (!is_writable(PHPWG_ROOT_PATH))
103  {
104    array_push(
105      $setup_errors,
106      sprintf(
107        l10n('Create the "%s" directory at the root of your Piwigo installation'),
108        $upload_base_dir
109        )
110      );
111  }
112}
113else
114{
115  if (!is_writable($upload_dir))
116  {
117    @chmod($upload_dir, 0777);
118
119    if (!is_writable($upload_dir))
120    {
121      array_push(
122        $setup_errors,
123        sprintf(
124          l10n('Give write access (chmod 777) to "%s" directory at the root of your Piwigo installation'),
125          $upload_base_dir
126          )
127        );
128    }
129  }
130}
131
132$template->assign(
133    array(
134      'setup_errors'=> $setup_errors,
135    )
136  );
137
138// +-----------------------------------------------------------------------+
139// |                           sending html code                           |
140// +-----------------------------------------------------------------------+
141
142$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
143?>
Note: See TracBrowser for help on using the repository browser.