Esempio n. 1
0
 /**
  * Original copyright information for the function from AutoMOD.
  * The function was almost totally changed by the authors of Upload Extensions.
  * @package       automod
  * @copyright (c) 2008 phpBB Group
  * @license       http://opensource.org/licenses/gpl-2.0.php GNU Public License
  *
  * @param string $action Requested action.
  * @return \filespec|bool
  */
 public function proceed_upload($action)
 {
     global $phpbb_root_path, $phpEx, $user, $request;
     //$can_upload = (@ini_get('file_uploads') == '0' || strtolower(@ini_get('file_uploads')) == 'off' || !@extension_loaded('zlib')) ? false : true;
     $user->add_lang('posting');
     // For error messages
     if (!class_exists('\\fileupload')) {
         include $phpbb_root_path . 'includes/functions_upload.' . $phpEx;
     }
     $upload = new \fileupload();
     $upload->set_allowed_extensions(array('zip'));
     // Only allow ZIP files
     // Make sure the ext/ directory exists and if it doesn't, create it
     if (!is_dir($phpbb_root_path . 'ext')) {
         if (!files::catch_errors(files::recursive_mkdir($phpbb_root_path . 'ext'))) {
             return false;
         }
     }
     if (!is_writable($phpbb_root_path . 'ext')) {
         files::catch_errors($user->lang['EXT_NOT_WRITABLE']);
         return false;
     }
     if (!is_dir(objects::$zip_dir)) {
         if (!files::catch_errors(files::recursive_mkdir(objects::$zip_dir))) {
             return false;
         }
     }
     if (!is_writable($phpbb_root_path . 'ext/' . objects::$upload_ext_name . '/tmp')) {
         if (!phpbb_chmod($phpbb_root_path . 'ext/' . objects::$upload_ext_name . '/tmp', CHMOD_READ | CHMOD_WRITE)) {
             files::catch_errors($user->lang['EXT_TMP_NOT_WRITABLE']);
             return false;
         }
     }
     $file = false;
     // Proceed with the upload
     if ($action == 'upload') {
         if (!$request->is_set("extupload", \phpbb\request\request_interface::FILES)) {
             files::catch_errors($user->lang['NO_UPLOAD_FILE']);
             return false;
         }
         $file = $upload->form_upload('extupload');
     } else {
         if ($action == 'upload_remote') {
             $php_ini = new \phpbb\php\ini();
             if (!$php_ini->get_bool('allow_url_fopen')) {
                 files::catch_errors($user->lang['EXT_ALLOW_URL_FOPEN_DISABLED']);
                 return false;
             }
             $remote_url = $request->variable('remote_upload', '');
             if (!extension_loaded('openssl') && 'https' === substr($remote_url, 0, 5)) {
                 files::catch_errors($user->lang['EXT_OPENSSL_DISABLED']);
                 return false;
             }
             $file = files::remote_upload($upload, $user, $remote_url);
         }
     }
     return $file;
 }