Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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:52 - Dateigröße: 9.25 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\attachment;
015   
016  use phpbb\auth\auth;
017  use \phpbb\cache\service;
018  use \phpbb\config\config;
019  use \phpbb\event\dispatcher;
020  use \phpbb\language\language;
021  use \phpbb\mimetype\guesser;
022  use \phpbb\plupload\plupload;
023  use \phpbb\user;
024   
025  /**
026   * Attachment upload class
027   */
028  class upload
029  {
030      /** @var auth */
031      protected $auth;
032   
033      /** @var service */
034      protected $cache;
035   
036      /** @var config */
037      protected $config;
038   
039      /** @var \phpbb\files\upload Upload class */
040      protected $files_upload;
041   
042      /** @var language */
043      protected $language;
044   
045      /** @var guesser Mimetype guesser */
046      protected $mimetype_guesser;
047   
048      /** @var dispatcher */
049      protected $phpbb_dispatcher;
050   
051      /** @var plupload Plupload */
052      protected $plupload;
053   
054      /** @var user */
055      protected $user;
056   
057      /** @var \phpbb\files\filespec Current filespec instance */
058      private $file;
059   
060      /** @var array File data */
061      private $file_data = array(
062          'error'    => array()
063      );
064   
065      /** @var array Extensions array */
066      private $extensions;
067   
068      /**
069       * Constructor for attachments upload class
070       *
071       * @param auth $auth
072       * @param service $cache
073       * @param config $config
074       * @param \phpbb\files\upload $files_upload
075       * @param language $language
076       * @param guesser $mimetype_guesser
077       * @param dispatcher $phpbb_dispatcher
078       * @param plupload $plupload
079       * @param user $user
080       * @param $phpbb_root_path
081       */
082      public function __construct(auth $auth, service $cache, config $config, \phpbb\files\upload $files_upload, language $language, guesser $mimetype_guesser, dispatcher $phpbb_dispatcher, plupload $plupload, user $user, $phpbb_root_path)
083      {
084          $this->auth = $auth;
085          $this->cache = $cache;
086          $this->config = $config;
087          $this->files_upload = $files_upload;
088          $this->language = $language;
089          $this->mimetype_guesser = $mimetype_guesser;
090          $this->phpbb_dispatcher = $phpbb_dispatcher;
091          $this->plupload = $plupload;
092          $this->user = $user;
093          $this->phpbb_root_path = $phpbb_root_path;
094      }
095   
096      /**
097       * Upload Attachment - filedata is generated here
098       * Uses upload class
099       *
100       * @param string            $form_name        The form name of the file upload input
101       * @param int            $forum_id        The id of the forum
102       * @param bool            $local            Whether the file is local or not
103       * @param string            $local_storage    The path to the local file
104       * @param bool            $is_message        Whether it is a PM or not
105       * @param array        $local_filedata    An file data object created for the local file
106       *
107       * @return array File data array
108       */
109      public function upload($form_name, $forum_id, $local = false, $local_storage = '', $is_message = false, $local_filedata = array())
110      {
111          $this->init_files_upload($forum_id, $is_message);
112   
113          $this->file_data['post_attach'] = $local || $this->files_upload->is_valid($form_name);
114   
115          if (!$this->file_data['post_attach'])
116          {
117              $this->file_data['error'][] = $this->language->lang('NO_UPLOAD_FORM_FOUND');
118              return $this->file_data;
119          }
120   
121          $this->file = ($local) ? $this->files_upload->handle_upload('files.types.local', $local_storage, $local_filedata) : $this->files_upload->handle_upload('files.types.form', $form_name);
122   
123          if ($this->file->init_error())
124          {
125              $this->file_data['post_attach'] = false;
126              return $this->file_data;
127          }
128   
129          // Whether the uploaded file is in the image category
130          $is_image = (isset($this->extensions[$this->file->get('extension')]['display_cat'])) ? $this->extensions[$this->file->get('extension')]['display_cat'] == ATTACHMENT_CATEGORY_IMAGE : false;
131   
132          if (!$this->auth->acl_get('a_') && !$this->auth->acl_get('m_', $forum_id))
133          {
134              // Check Image Size, if it is an image
135              if ($is_image)
136              {
137                  $this->file->upload->set_allowed_dimensions(0, 0, $this->config['img_max_width'], $this->config['img_max_height']);
138              }
139   
140              // Admins and mods are allowed to exceed the allowed filesize
141              if (!empty($this->extensions[$this->file->get('extension')]['max_filesize']))
142              {
143                  $allowed_filesize = $this->extensions[$this->file->get('extension')]['max_filesize'];
144              }
145              else
146              {
147                  $allowed_filesize = ($is_message) ? $this->config['max_filesize_pm'] : $this->config['max_filesize'];
148              }
149   
150              $this->file->upload->set_max_filesize($allowed_filesize);
151          }
152   
153          $this->file->clean_filename('unique', $this->user->data['user_id'] . '_');
154   
155          // Are we uploading an image *and* this image being within the image category?
156          // Only then perform additional image checks.
157          $this->file->move_file($this->config['upload_path'], false, !$is_image);
158   
159          // Do we have to create a thumbnail?
160          $this->file_data['thumbnail'] = ($is_image && $this->config['img_create_thumbnail']) ? 1 : 0;
161   
162          // Make sure the image category only holds valid images...
163          $this->check_image($is_image);
164   
165          if (sizeof($this->file->error))
166          {
167              $this->file->remove();
168              $this->file_data['error'] = array_merge($this->file_data['error'], $this->file->error);
169              $this->file_data['post_attach'] = false;
170   
171              return $this->file_data;
172          }
173   
174          $this->fill_file_data();
175   
176          $filedata = $this->file_data;
177   
178          /**
179           * Event to modify uploaded file before submit to the post
180           *
181           * @event core.modify_uploaded_file
182           * @var    array    filedata    Array containing uploaded file data
183           * @var    bool    is_image    Flag indicating if the file is an image
184           * @since 3.1.0-RC3
185           */
186          $vars = array(
187              'filedata',
188              'is_image',
189          );
190          extract($this->phpbb_dispatcher->trigger_event('core.modify_uploaded_file', compact($vars)));
191          $this->file_data = $filedata;
192          unset($filedata);
193   
194          // Check for attachment quota and free space
195          if (!$this->check_attach_quota() || !$this->check_disk_space())
196          {
197              return $this->file_data;
198          }
199   
200          // Create Thumbnail
201          $this->create_thumbnail();
202   
203          return $this->file_data;
204      }
205   
206      /**
207       * Create thumbnail for file if necessary
208       *
209       * @return array Updated $filedata
210       */
211      protected function create_thumbnail()
212      {
213          if ($this->file_data['thumbnail'])
214          {
215              $source = $this->file->get('destination_file');
216              $destination = $this->file->get('destination_path') . '/thumb_' . $this->file->get('realname');
217   
218              if (!create_thumbnail($source, $destination, $this->file->get('mimetype')))
219              {
220                  $this->file_data['thumbnail'] = 0;
221              }
222          }
223      }
224   
225      /**
226       * Init files upload class
227       *
228       * @param int $forum_id Forum ID
229       * @param bool $is_message Whether attachment is inside PM or not
230       */
231      protected function init_files_upload($forum_id, $is_message)
232      {
233          if ($this->config['check_attachment_content'] && isset($this->config['mime_triggers']))
234          {
235              $this->files_upload->set_disallowed_content(explode('|', $this->config['mime_triggers']));
236          }
237          else if (!$this->config['check_attachment_content'])
238          {
239              $this->files_upload->set_disallowed_content(array());
240          }
241   
242          $this->extensions = $this->cache->obtain_attach_extensions((($is_message) ? false : (int) $forum_id));
243          $this->files_upload->set_allowed_extensions(array_keys($this->extensions['_allowed_']));
244      }
245   
246      /**
247       * Check if uploaded file is really an image
248       *
249       * @param bool $is_image Whether file is image
250       */
251      protected function check_image($is_image)
252      {
253          // Make sure the image category only holds valid images...
254          if ($is_image && !$this->file->is_image())
255          {
256              $this->file->remove();
257   
258              if ($this->plupload && $this->plupload->is_active())
259              {
260                  $this->plupload->emit_error(104, 'ATTACHED_IMAGE_NOT_IMAGE');
261              }
262   
263              // If this error occurs a user tried to exploit an IE Bug by renaming extensions
264              // Since the image category is displaying content inline we need to catch this.
265              $this->file->set_error($this->language->lang('ATTACHED_IMAGE_NOT_IMAGE'));
266          }
267      }
268   
269      /**
270       * Check if attachment quota was reached
271       *
272       * @return bool False if attachment quota was reached, true if not
273       */
274      protected function check_attach_quota()
275      {
276          if ($this->config['attachment_quota'])
277          {
278              if (intval($this->config['upload_dir_size']) + $this->file->get('filesize') > $this->config['attachment_quota'])
279              {
280                  $this->file_data['error'][] = $this->language->lang('ATTACH_QUOTA_REACHED');
281                  $this->file_data['post_attach'] = false;
282   
283                  $this->file->remove();
284   
285                  return false;
286              }
287          }
288   
289          return true;
290      }
291   
292      /**
293       * Check if there is enough free space available on disk
294       *
295       * @return bool True if disk space is available, false if not
296       */
297      protected function check_disk_space()
298      {
299          if ($free_space = @disk_free_space($this->phpbb_root_path . $this->config['upload_path']))
300          {
301              if ($free_space <= $this->file->get('filesize'))
302              {
303                  if ($this->auth->acl_get('a_'))
304                  {
305                      $this->file_data['error'][] = $this->language->lang('ATTACH_DISK_FULL');
306                  }
307                  else
308                  {
309                      $this->file_data['error'][] = $this->language->lang('ATTACH_QUOTA_REACHED');
310                  }
311                  $this->file_data['post_attach'] = false;
312   
313                  $this->file->remove();
314   
315                  return false;
316              }
317          }
318   
319          return true;
320      }
321   
322      /**
323       * Fills file data with file information and current time as filetime
324       */
325      protected function fill_file_data()
326      {
327          $this->file_data['filesize'] = $this->file->get('filesize');
328          $this->file_data['mimetype'] = $this->file->get('mimetype');
329          $this->file_data['extension'] = $this->file->get('extension');
330          $this->file_data['physical_filename'] = $this->file->get('realname');
331          $this->file_data['real_filename'] = $this->file->get('uploadname');
332          $this->file_data['filetime'] = time();
333      }
334  }
335