Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

upload.php

Zuletzt modifiziert: 09.10.2024, 12:54 - Dateigröße: 5.64 KiB


001  <?php
002  /**
003  *
004  * This file is part of the phpBB Forum Software package.
005  *
006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
007  * @license GNU General Public License, version 2 (GPL-2.0)
008  *
009  * For full copyright and license information, please see
010  * the docs/CREDITS.txt file.
011  *
012  */
013   
014  namespace phpbb\avatar\driver;
015   
016  /**
017  * Handles avatars uploaded to the board
018  */
019  class upload extends \phpbb\avatar\driver\driver
020  {
021      /**
022      * @var \phpbb\mimetype\guesser
023      */
024      protected $mimetype_guesser;
025   
026      /**
027      * Construct a driver object
028      *
029      * @param \phpbb\config\config $config phpBB configuration
030      * @param string $phpbb_root_path Path to the phpBB root
031      * @param string $php_ext PHP file extension
032      * @param \phpbb_path_helper $path_helper phpBB path helper
033      * @param \phpbb\mimetype\guesser $mimetype_guesser Mimetype guesser
034      * @param \phpbb\cache\driver\driver_interface $cache Cache driver
035      */
036      public function __construct(\phpbb\config\config $config, $phpbb_root_path, $php_ext, \phpbb\path_helper $path_helper, \phpbb\mimetype\guesser $mimetype_guesser, \phpbb\cache\driver\driver_interface $cache = null)
037      {
038          $this->config = $config;
039          $this->phpbb_root_path = $phpbb_root_path;
040          $this->php_ext = $php_ext;
041          $this->path_helper = $path_helper;
042          $this->mimetype_guesser = $mimetype_guesser;
043          $this->cache = $cache;
044      }
045   
046      /**
047      * {@inheritdoc}
048      */
049      public function get_data($row, $ignore_config = false)
050      {
051          return array(
052              'src' => $this->path_helper->get_web_root_path() . 'download/file.' . $this->php_ext . '?avatar=' . $row['avatar'],
053              'width' => $row['avatar_width'],
054              'height' => $row['avatar_height'],
055          );
056      }
057   
058      /**
059      * {@inheritdoc}
060      */
061      public function prepare_form($request, $template, $user, $row, &$error)
062      {
063          if (!$this->can_upload())
064          {
065              return false;
066          }
067   
068          $template->assign_vars(array(
069              'S_UPLOAD_AVATAR_URL' => ($this->config['allow_avatar_remote_upload']) ? true : false,
070              'AVATAR_UPLOAD_SIZE' => $this->config['avatar_filesize'],
071          ));
072   
073          return true;
074      }
075   
076      /**
077      * {@inheritdoc}
078      */
079      public function process_form($request, $template, $user, $row, &$error)
080      {
081          if (!$this->can_upload())
082          {
083              return false;
084          }
085   
086          if (!class_exists('fileupload'))
087          {
088              include($this->phpbb_root_path . 'includes/functions_upload.' . $this->php_ext);
089          }
090   
091          $upload = new \fileupload('AVATAR_', $this->allowed_extensions, $this->config['avatar_filesize'], $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], (isset($this->config['mime_triggers']) ? explode('|', $this->config['mime_triggers']) : false));
092   
093          $url = $request->variable('avatar_upload_url', '');
094          $upload_file = $request->file('avatar_upload_file');
095   
096          if (!empty($upload_file['name']))
097          {
098              $file = $upload->form_upload('avatar_upload_file', $this->mimetype_guesser);
099          }
100          else if (!empty($this->config['allow_avatar_remote_upload']) && !empty($url))
101          {
102              if (!preg_match('#^(http|https|ftp)://#i', $url))
103              {
104                  $url = 'http://' . $url;
105              }
106   
107              if (!function_exists('validate_data'))
108              {
109                  require($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext);
110              }
111   
112              $validate_array = validate_data(
113                  array(
114                      'url' => $url,
115                  ),
116                  array(
117                      'url' => array('string', true, 5, 255),
118                  )
119              );
120   
121              $error = array_merge($error, $validate_array);
122   
123              if (!empty($error))
124              {
125                  return false;
126              }
127   
128              $file = $upload->remote_upload($url, $this->mimetype_guesser);
129          }
130          else
131          {
132              return false;
133          }
134   
135          $prefix = $this->config['avatar_salt'] . '_';
136          $file->clean_filename('avatar', $prefix, $row['id']);
137   
138          $destination = $this->config['avatar_path'];
139   
140          // Adjust destination path (no trailing slash)
141          if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\')
142          {
143              $destination = substr($destination, 0, -1);
144          }
145   
146          $destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination);
147          if ($destination && ($destination[0] == '/' || $destination[0] == "\\"))
148          {
149              $destination = '';
150          }
151   
152          // Move file and overwrite any existing image
153          $file->move_file($destination, true);
154   
155          if (sizeof($file->error))
156          {
157              $file->remove();
158              $error = array_merge($error, $file->error);
159              return false;
160          }
161   
162          return array(
163              'avatar' => $row['id'] . '_' . time() . '.' . $file->get('extension'),
164              'avatar_width' => $file->get('width'),
165              'avatar_height' => $file->get('height'),
166          );
167      }
168   
169      /**
170      * {@inheritdoc}
171      */
172      public function prepare_form_acp($user)
173      {
174          return array(
175              'allow_avatar_remote_upload'=> array('lang' => 'ALLOW_REMOTE_UPLOAD', 'validate' => 'bool',    'type' => 'radio:yes_no', 'explain' => true),
176              'avatar_filesize'        => array('lang' => 'MAX_FILESIZE',            'validate' => 'int:0',    'type' => 'number:0', 'explain' => true, 'append' => ' ' . $user->lang['BYTES']),
177              'avatar_path'            => array('lang' => 'AVATAR_STORAGE_PATH',    'validate' => 'rpath',    'type' => 'text:20:255', 'explain' => true),
178          );
179      }
180   
181      /**
182      * {@inheritdoc}
183      */
184      public function delete($row)
185      {
186          $ext = substr(strrchr($row['avatar'], '.'), 1);
187          $filename = $this->phpbb_root_path . $this->config['avatar_path'] . '/' . $this->config['avatar_salt'] . '_' . $row['id'] . '.' . $ext;
188   
189          if (file_exists($filename))
190          {
191              @unlink($filename);
192          }
193   
194          return true;
195      }
196   
197      /**
198      * {@inheritdoc}
199      */
200      public function get_template_name()
201      {
202          return 'ucp_avatar_options_upload.html';
203      }
204   
205      /**
206      * Check if user is able to upload an avatar
207      *
208      * @return bool True if user can upload, false if not
209      */
210      protected function can_upload()
211      {
212          return (file_exists($this->phpbb_root_path . $this->config['avatar_path']) && phpbb_is_writable($this->phpbb_root_path . $this->config['avatar_path']) && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on'));
213      }
214  }
215