source: extensions/PersoFavicon/admin/admin.php @ 19391

Last change on this file since 19391 was 19391, checked in by plg, 11 years ago

Better management on error code/message provided by PHP on file upload

No need to add a MAX_FILE_SIZE limit on HTML form, it makes the error
message less readable than the specific PHP error message.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 2.9 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4global $template, $conf, $user, $page;
5include_once(PHPWG_ROOT_PATH .'admin/include/tabsheet.class.php');
6load_language('plugin.lang', PFI_PATH);
7$my_base_url = get_admin_plugin_menu_link(__FILE__);
8
9// +-----------------------------------------------------------------------+
10// | Check Access and exit when user status is not ok                      |
11// +-----------------------------------------------------------------------+
12check_status(ACCESS_ADMINISTRATOR);
13
14//-------------------------------------------------------- sections definitions
15
16// Gestion des onglets
17if (!isset($_GET['tab']))
18    $page['tab'] = 'pfi';
19else
20    $page['tab'] = $_GET['tab'];
21
22$tabsheet = new tabsheet();
23$tabsheet->add('pfi',
24               l10n('pfi_ajout'),
25               $my_base_url.'&amp;tab=pfi');
26$tabsheet->add('help',
27               l10n('help'),
28               $my_base_url.'&amp;tab=help');
29$tabsheet->select($page['tab']);
30$tabsheet->assign();
31
32switch ($page['tab'])
33{
34// Onglet gestion de onglet ajout icône
35  case 'pfi':
36$blockdesc = 'pfi';
37$template->assign(
38        $blockdesc,
39        array(
40          'meta'=>l10n('pfi_name'),
41          ));
42
43$filename = PHPWG_ROOT_PATH.PWG_LOCAL_DIR .'favicon.ico';
44if (file_exists($filename)) {$template->assign('ICO',$filename);}
45
46if (isset($_POST['submitpfi']) and !is_adviser())
47{
48
49$content_dir = PHPWG_ROOT_PATH.PWG_LOCAL_DIR;   
50$tmp_file = $_FILES['pfi']['tmp_name'];
51
52if ($_FILES['pfi']['error'] !== UPLOAD_ERR_OK)
53{
54  include_once(PHPWG_ROOT_PATH .'admin/include/functions_upload.inc.php');
55  $error_message = file_upload_error_message($_FILES['pfi']['error']);
56  array_push( $page['errors'], $error_message);
57  break;
58}
59
60  if( !is_uploaded_file($tmp_file) )
61    {
62                array_push( $page['errors'], l10n('pfi_erreur_vide') );
63                break;
64    }
65
66$type_file = strrchr($_FILES['pfi']['name'], '.');
67  if( !strstr($type_file, 'ico'))
68    {
69                array_push( $page['errors'], l10n('pfi_erreur_ext'));
70                break;
71        }
72
73       
74$taille_maxi = 5120;
75$taille = filesize($_FILES['pfi']['tmp_name']);
76  if($taille>$taille_maxi)
77        {
78                array_push($page['errors'], l10n('pfi_erreur_taille'));
79                break;
80        }       
81
82$filename = PHPWG_ROOT_PATH.PWG_LOCAL_DIR .'favicon.ico';
83if (file_exists($filename)) 
84        {
85                array_push($page['infos'], l10n('pfi_erreur_exist'));
86        }
87
88$name_file = $_FILES['pfi']['name'];
89  if( preg_match('#[\x00-\x1F\x7F-\x9F/\\\\]#', $name_file) )
90        {
91  array_push( $page['infos'], l10n('pfi_erreur_nom') );
92          break;
93        }
94  else if(
95  !move_uploaded_file($tmp_file, $content_dir . 'favicon.ico') )
96        {
97  array_push( $page['errors'], l10n('pfi_erreur_mouve') );
98  break;
99        }
100  array_push( $page['infos'], l10n('pfi_ok') );
101
102
103}
104 
105    break;
106
107  case 'help':
108  $blockdesc = 'help';
109$template->assign(
110        $blockdesc,
111        array(
112          'meta'=>l10n('pfi_name'),
113          ));
114 
115        break;
116       
117} 
118
119$template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/admin.tpl')); 
120$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
121?>
Note: See TracBrowser for help on using the repository browser.