Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
accept_file_upload.php
1 <?php
25 if ((!is_array($_FILES)) || empty($_FILES)) exit();
26 
27 // get init.inc to do all the hard work figuring out who's logged in etc
28 require_once dirname(dirname(dirname(__FILE__))).'/include/init.inc';
29 
30 // kick out the wrong types of people
31 if (empty($GLOBALS['SQ_SYSTEM']->user) || !$GLOBALS['SQ_SYSTEM']->user->canAccessBackend()) {
32  trigger_localised_error('SYS0028', E_USER_ERROR);
33  exit();
34 }
35 
36 // copy all uploaded files, including arrays of files, to the temp dir
37 require_once SQ_FUDGE_PATH.'/general/file_system.inc';
38 $ms = $GLOBALS['SQ_SYSTEM']->getMessagingService();
39 $ms->openLog();
40 foreach ($_FILES as $id => $details) {
41  if (is_array($details['name'])) {
42  foreach ($_FILES[$id]['name'] as $index => $name) {
43  if (!empty($name)) {
44  $file_name = strtolower(str_replace(' ', '_', $name));
45  while (file_exists(SQ_TEMP_PATH.'/'.$file_name)) $file_name = increment_filename($file_name);
46  if (move_uploaded_file($_FILES[$id]['tmp_name'][$index], SQ_TEMP_PATH.'/'.$file_name)) {
47  print("\nOK ".$file_name."\n");
48  } else {
49  trigger_localised_error('SYS0009', E_USER_WARNING);
50  }
51  }
52  }
53  } else {
54  if (!empty($details['name'])) {
55  $file_name = strtolower(str_replace(' ', '_', $details['name']));
56  while (file_exists(SQ_TEMP_PATH.'/'.$file_name)) $file_name = increment_filename($file_name);
57  if (move_uploaded_file($_FILES[$id]['tmp_name'], SQ_TEMP_PATH.'/'.$file_name)) {
58  print("\nOK ".$file_name."\n");
59  } else {
60  trigger_localised_error('SYS0009', E_USER_WARNING);
61  }
62  }
63  }
64 }
65 $ms->closeLog();
66 
67 ?>