本文整理汇总了PHP中fileupload::set_allowed_extensions方法的典型用法代码示例。如果您正苦于以下问题:PHP fileupload::set_allowed_extensions方法的具体用法?PHP fileupload::set_allowed_extensions怎么用?PHP fileupload::set_allowed_extensions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fileupload
的用法示例。
在下文中一共展示了fileupload::set_allowed_extensions方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: main
public function main($id, $mode)
{
global $config, $user, $template, $request, $phpbb_container, $phpbb_root_path, $phpEx;
$user->add_lang_ext('tas2580/mobilenotifier', 'common');
$wa = $phpbb_container->get('tas2580.mobilenotifier.src.helper');
$this->tpl_name = 'acp_mobilenotifier_body';
$this->page_title = $user->lang('ACP_MOBILENOTIFIER_TITLE');
add_form_key('acp_mobilenotifier');
// Form is submitted
if ($request->is_set_post('submit')) {
if (!check_form_key('acp_mobilenotifier')) {
trigger_error($user->lang('FORM_INVALID') . adm_back_link($this->u_action), E_USER_WARNING);
}
$config->set('whatsapp_sender', $request->variable('sender', ''));
$config->set('whatsapp_password', $request->variable('password', ''));
$config->set('whatsapp_status', $request->variable('status', ''));
$config->set('whatsapp_default_cc', $request->variable('default_cc', ''));
$wa->update_status($config['whatsapp_status']);
if ($request->file('image')) {
include_once $phpbb_root_path . 'includes/functions_upload.' . $phpEx;
$upload = new \fileupload();
$upload->set_allowed_extensions(array('jpg', 'png', 'gif'));
$file = $upload->form_upload('image');
if ($file->filename) {
$wa->update_picture($file->filename);
}
}
trigger_error($user->lang('ACP_SAVED') . adm_back_link($this->u_action));
}
$template->assign_vars(array('WA_VERSION' => WA_VER, 'U_ACTION' => $this->u_action, 'SENDER' => isset($config['whatsapp_sender']) ? $config['whatsapp_sender'] : '', 'PASSWORD' => isset($config['whatsapp_password']) ? $config['whatsapp_password'] : '', 'STATUS' => isset($config['whatsapp_status']) ? $config['whatsapp_status'] : '', 'CC_SELECT' => $wa->cc_select(isset($config['whatsapp_default_cc']) ? $config['whatsapp_default_cc'] : '')));
}
示例2: upload_attachment
/**
* Upload Attachment - filedata is generated here
* Uses upload class
*/
function upload_attachment($form_name, $forum_id, $local = false, $local_storage = '', $is_message = false, $local_filedata = false)
{
global $auth, $user, $config, $db, $cache;
global $phpbb_root_path, $phpEx;
$filedata = array('error' => array());
include_once $phpbb_root_path . 'includes/functions_upload.' . $phpEx;
$upload = new fileupload();
if ($config['check_attachment_content'] && isset($config['mime_triggers'])) {
$upload->set_disallowed_content(explode('|', $config['mime_triggers']));
}
if (!$local) {
$filedata['post_attach'] = $upload->is_valid($form_name) ? true : false;
} else {
$filedata['post_attach'] = true;
}
if (!$filedata['post_attach']) {
$filedata['error'][] = $user->lang['NO_UPLOAD_FORM_FOUND'];
return $filedata;
}
$extensions = $cache->obtain_attach_extensions($is_message ? false : (int) $forum_id);
$upload->set_allowed_extensions(array_keys($extensions['_allowed_']));
$file = $local ? $upload->local_upload($local_storage, $local_filedata) : $upload->form_upload($form_name);
if ($file->init_error) {
$filedata['post_attach'] = false;
return $filedata;
}
$cat_id = isset($extensions[$file->get('extension')]['display_cat']) ? $extensions[$file->get('extension')]['display_cat'] : ATTACHMENT_CATEGORY_NONE;
// Make sure the image category only holds valid images...
if ($cat_id == ATTACHMENT_CATEGORY_IMAGE && !$file->is_image()) {
$file->remove();
// If this error occurs a user tried to exploit an IE Bug by renaming extensions
// Since the image category is displaying content inline we need to catch this.
trigger_error($user->lang['ATTACHED_IMAGE_NOT_IMAGE']);
}
// Do we have to create a thumbnail?
$filedata['thumbnail'] = $cat_id == ATTACHMENT_CATEGORY_IMAGE && $config['img_create_thumbnail'] ? 1 : 0;
// Check Image Size, if it is an image
if (!$auth->acl_get('a_') && !$auth->acl_get('m_', $forum_id) && $cat_id == ATTACHMENT_CATEGORY_IMAGE) {
$file->upload->set_allowed_dimensions(0, 0, $config['img_max_width'], $config['img_max_height']);
}
// Admins and mods are allowed to exceed the allowed filesize
if (!$auth->acl_get('a_') && !$auth->acl_get('m_', $forum_id)) {
if (!empty($extensions[$file->get('extension')]['max_filesize'])) {
$allowed_filesize = $extensions[$file->get('extension')]['max_filesize'];
} else {
$allowed_filesize = $is_message ? $config['max_filesize_pm'] : $config['max_filesize'];
}
$file->upload->set_max_filesize($allowed_filesize);
}
$file->clean_filename('unique', $user->data['user_id'] . '_');
// Are we uploading an image *and* this image being within the image category? Only then perform additional image checks.
$no_image = $cat_id == ATTACHMENT_CATEGORY_IMAGE ? false : true;
$file->move_file($config['upload_path'], false, $no_image);
if (sizeof($file->error)) {
$file->remove();
$filedata['error'] = array_merge($filedata['error'], $file->error);
$filedata['post_attach'] = false;
return $filedata;
}
$filedata['filesize'] = $file->get('filesize');
$filedata['mimetype'] = $file->get('mimetype');
$filedata['extension'] = $file->get('extension');
$filedata['physical_filename'] = $file->get('realname');
$filedata['real_filename'] = $file->get('uploadname');
$filedata['filetime'] = time();
// Check our complete quota
if ($config['attachment_quota']) {
if ($config['upload_dir_size'] + $file->get('filesize') > $config['attachment_quota']) {
$filedata['error'][] = $user->lang['ATTACH_QUOTA_REACHED'];
$filedata['post_attach'] = false;
$file->remove();
return $filedata;
}
}
// Check free disk space
if ($free_space = @disk_free_space($phpbb_root_path . $config['upload_path'])) {
if ($free_space <= $file->get('filesize')) {
$filedata['error'][] = $user->lang['ATTACH_QUOTA_REACHED'];
$filedata['post_attach'] = false;
$file->remove();
return $filedata;
}
}
// Create Thumbnail
if ($filedata['thumbnail']) {
$source = $file->get('destination_file');
$destination = $file->get('destination_path') . '/thumb_' . $file->get('realname');
if (!create_thumbnail($source, $destination, $file->get('mimetype'))) {
$filedata['thumbnail'] = 0;
}
}
return $filedata;
}
示例3: upload_attachment
function upload_attachment($form_name, $forum_id, $local = false, $local_storage = '', $is_message = false)
{
global $_CLASS, $config;
$filedata = array();
$filedata['error'] = array();
include_once SITE_FILE_ROOT . 'includes/forums/functions_upload.php';
$upload = new fileupload();
if (!$local) {
$filedata['post_attach'] = $upload->is_valid($form_name) ? true : false;
} else {
$filedata['post_attach'] = true;
}
if (!$filedata['post_attach']) {
$filedata['error'][] = 'No filedata found';
return $filedata;
}
$extensions = obtain_attach_extensions($forum_id);
if (!empty($extensions['_allowed_'])) {
$upload->set_allowed_extensions(array_keys($extensions['_allowed_']));
}
if ($local) {
$file = $upload->local_upload($local_storage);
} else {
$file = $upload->form_upload($form_name);
}
if ($file->init_error) {
$filedata['post_attach'] = false;
return $filedata;
}
$cat_id = isset($extensions[$file->get('extension')]['display_cat']) ? $extensions[$file->get('extension')]['display_cat'] : ATTACHMENT_CATEGORY_NONE;
// Do we have to create a thumbnail?
$filedata['thumbnail'] = $cat_id == ATTACHMENT_CATEGORY_IMAGE && $config['img_create_thumbnail'] ? 1 : 0;
// Check Image Size, if it is an image
if (!$_CLASS['auth']->acl_gets('m_', 'a_') && $cat_id == ATTACHMENT_CATEGORY_IMAGE) {
$file->upload->set_allowed_dimensions(0, 0, $config['img_max_width'], $config['img_max_height']);
}
if (!$_CLASS['auth']->acl_gets('a_', 'm_')) {
$allowed_filesize = $extensions[$file->get('extension')]['max_filesize'] != 0 ? $extensions[$file->get('extension')]['max_filesize'] : ($is_message ? $config['max_filesize_pm'] : $config['max_filesize']);
$file->upload->set_max_filesize($allowed_filesize);
}
$file->clean_filename('unique', $_CLASS['core_user']->data['user_id'] . '_');
$file->move_file($config['upload_path']);
if (!empty($file->error)) {
$file->remove();
$filedata['error'] = array_merge($filedata['error'], $file->error);
$filedata['post_attach'] = false;
return $filedata;
}
$filedata['filesize'] = $file->get('filesize');
$filedata['mimetype'] = $file->get('mimetype');
$filedata['extension'] = $file->get('extension');
$filedata['physical_filename'] = $file->get('realname');
$filedata['real_filename'] = $file->get('uploadname');
$filedata['filetime'] = time();
// Check our complete quota
if ($config['attachment_quota']) {
if ($config['upload_dir_size'] + $file->get('filesize') > $config['attachment_quota']) {
$filedata['error'][] = $_CLASS['core_user']->lang['ATTACH_QUOTA_REACHED'];
$filedata['post_attach'] = false;
$file->remove();
return $filedata;
}
}
// Check free disk space
if ($free_space = @disk_free_space($config['upload_path'])) {
if ($free_space <= $file->get('filesize')) {
$filedata['error'][] = $_CLASS['core_user']->lang['ATTACH_QUOTA_REACHED'];
$filedata['post_attach'] = false;
$file->remove();
return $filedata;
}
}
// Create Thumbnail
if ($filedata['thumbnail']) {
$source = $file->get('destination_file');
$destination = $file->get('destination_path') . '/thumb_' . $file->get('realname');
if (!create_thumbnail($source, $destination, $file->get('mimetype'))) {
$filedata['thumbnail'] = 0;
}
}
return $filedata;
}
示例4: implode
/**
*
* @package automod
* @copyright (c) 2008 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
*
*/
function upload_ext($action)
{
$this->listzip();
$this->user->add_lang('posting');
// For error messages
include $this->phpbb_root_path . 'includes/functions_upload.' . $this->php_ext;
$upload = new \fileupload();
$upload->set_allowed_extensions(array('zip'));
// Only allow ZIP files
if (!is_writable($this->ext_dir)) {
$this->trigger_error($this->user->lang['EXT_NOT_WRITABLE'] . $this->back_link, E_USER_WARNING);
return false;
}
$upload_dir = $this->ext_dir;
// Make sure the ext/ directory exists and if it doesn't, create it
if (!is_dir($this->ext_dir)) {
$this->recursive_mkdir($this->ext_dir);
}
// Proceed with the upload
if ($action == 'upload') {
$file = $upload->form_upload('extupload');
} else {
if ($action == 'upload_remote') {
$file = $this->remote_upload($upload, $this->request->variable('remote_upload', ''));
}
}
if ($action != 'upload_local') {
if (empty($file->filename)) {
$this->trigger_error((sizeof($file->error) ? implode('<br />', $file->error) : $this->user->lang['NO_UPLOAD_FILE']) . $this->back_link, E_USER_WARNING);
return false;
} else {
if ($file->init_error || sizeof($file->error)) {
$file->remove();
$this->trigger_error((sizeof($file->error) ? implode('<br />', $file->error) : $this->user->lang['EXT_UPLOAD_INIT_FAIL']) . $this->back_link, E_USER_WARNING);
return false;
}
}
$file->clean_filename('real');
$file->move_file(str_replace($this->phpbb_root_path, '', $upload_dir), true, true);
if (sizeof($file->error)) {
$file->remove();
$this->trigger_error(implode('<br />', $file->error) . $this->back_link, E_USER_WARNING);
return false;
}
$dest_file = $file->destination_file;
} else {
$dest_file = $this->phpbb_root_path . 'ext/' . $this->request->variable('local_upload', '');
}
include $this->phpbb_root_path . 'includes/functions_compress.' . $this->php_ext;
$zip = new \ZipArchive();
$res = $zip->open($dest_file);
if ($res !== true) {
$this->trigger_error($this->user->lang['ziperror'][$res] . $this->back_link, E_USER_WARNING);
return false;
}
$zip->extractTo($this->phpbb_root_path . 'ext/tmp');
$zip->close();
$style_path = $this->get_style_path($this->phpbb_root_path . 'ext/tmp');
if (!$style_path) {
$this->trigger_error($this->user->lang['ACP_UPLOAD_STYLE_ERROR_COMP'] . $this->back_link, E_USER_WARNING);
return false;
}
$style_cfg = $this->read_style_cfg($style_path);
$destination = str_replace(' ', '_', $style_cfg['name']);
if ($style_cfg['phpbb_version'] != $this->config['version']) {
$this->trigger_error($this->user->lang['ACP_UPLOAD_STYLE_ERROR_DEST'] . $this->back_link, E_USER_WARNING);
return false;
}
$display_name = $style_cfg['name'];
if (!isset($style_cfg['name'])) {
$this->rrmdir($this->phpbb_root_path . 'ext/tmp');
if ($action != 'upload_local') {
$file->remove();
}
$this->trigger_error($this->user->lang['NOT_AN_STYLE'] . $this->back_link, E_USER_WARNING);
return false;
}
$source = substr($style_path, 0, -10);
/* Delete the previous version of style files - we're able to update them. */
if (is_dir($this->phpbb_root_path . 'styles/' . $destination)) {
$this->rrmdir($this->phpbb_root_path . 'styles/' . $destination);
}
$this->rcopy($source, $this->phpbb_root_path . 'styles/' . $destination);
$this->rrmdir($this->phpbb_root_path . 'ext/tmp');
$this->template->assign_block_vars('authors', array('AUTHOR' => $style_cfg['copyright']));
$string = @file_get_contents($this->phpbb_root_path . 'styles/' . $destination . '/style.cfg');
if ($string !== false) {
$readme = highlight_string($string, true);
} else {
$readme = false;
}
$this->template->assign_vars(array('S_UPLOADED' => $display_name, 'FILETREE' => \filetree::php_file_tree($this->phpbb_root_path . 'styles/' . $destination, $display_name, $this->main_link), 'S_ACTION' => $this->phpbb_root_path . '/adm/index.php?i=acp_styles&sid=' . $this->user->session_id . '&mode=install&action=install&hash=' . generate_link_hash('install') . '&dir=' . urlencode($destination), 'S_ACTION_BACK' => $this->main_link, 'U_ACTION' => $this->u_action, 'README_MARKDOWN' => $readme, 'FILENAME' => $string !== false ? 'style.cfg' : '', 'CONTENT' => $string !== false ? highlight_string($string, true) : ''));
// Remove the uploaded archive file
//.........这里部分代码省略.........
示例5: main
public function main($id, $mode)
{
global $config, $user, $template, $request, $phpbb_container, $phpbb_root_path, $phpEx;
$user->add_lang_ext('tas2580/mobilenotifier', 'common');
$wa = $phpbb_container->get('tas2580.mobilenotifier.src.helper');
switch ($mode) {
case 'settings':
$this->tpl_name = 'acp_mobilenotifier_settings';
$this->page_title = $user->lang('ACP_MOBILENOTIFIER_SETTINGS');
$data_foler = $phpbb_root_path . 'ext/tas2580/mobilenotifier/vendor/Chat-API/wadata';
add_form_key('acp_mobilenotifier');
// Form is submitted
if ($request->is_set_post('submit')) {
if (!check_form_key('acp_mobilenotifier')) {
trigger_error($user->lang('FORM_INVALID') . adm_back_link($this->u_action), E_USER_WARNING);
}
$sender = $request->variable('sender', '');
$password = $request->variable('password', '');
$status = $request->variable('status', '');
if (!empty($sender) && !empty($password)) {
if ($status != $config['whatsapp_status']) {
$wa->update_status($status);
}
if ($request->file('image')) {
include_once $phpbb_root_path . 'includes/functions_upload.' . $phpEx;
$upload = new \fileupload();
$upload->set_allowed_extensions(array('jpg', 'png', 'gif'));
$file = $upload->form_upload('image');
if ($file->filename) {
$wa->update_picture($file->filename);
}
}
}
$config->set('whatsapp_sender', $sender);
$config->set('whatsapp_password', $password);
$config->set('whatsapp_status', $status);
$config->set('whatsapp_default_cc', $request->variable('default_cc', ''));
trigger_error($user->lang('ACP_SAVED') . adm_back_link($this->u_action));
}
$template->assign_vars(array('DATA_WRITABLE' => is_writable($data_foler), 'DATA_FOLDER_NOT_WRITABLE' => $user->lang('DATA_FOLDER_NOT_WRITABLE', $data_foler), 'WA_VERSION' => \Constants::WHATSAPP_VER, 'U_ACTION' => $this->u_action, 'SENDER' => isset($config['whatsapp_sender']) ? $config['whatsapp_sender'] : '', 'PASSWORD' => isset($config['whatsapp_password']) ? $config['whatsapp_password'] : '', 'STATUS' => isset($config['whatsapp_status']) ? $config['whatsapp_status'] : '', 'CC_SELECT' => $wa->cc_select(isset($config['whatsapp_default_cc']) ? $config['whatsapp_default_cc'] : '')));
break;
case 'debug':
$this->tpl_name = 'acp_mobilenotifier_debug';
$this->page_title = $user->lang('ACP_MOBILENOTIFIER_DEBUG');
if ($request->is_set_post('get_code')) {
$method = $request->variable('method', 'sms');
$response = $wa->register('', $method);
trigger_error($user->lang('CODE_REQUEST_SEND', $method) . adm_back_link($this->u_action));
}
if ($request->is_set_post('get_pw')) {
$code = $request->variable('code', '');
$response = $wa->register($code);
$config->set('whatsapp_password', $response);
trigger_error($user->lang('PASSWORD_REQUEST_SEND') . adm_back_link($this->u_action));
}
if ($request->is_set_post('test')) {
$nr = $request->variable('nr', '');
$response = $wa->send_test($nr, $user->lang('TEST_MESSAGE', generate_board_url()));
trigger_error($user->lang('TEST_MESSAGE_SEND', $nr) . adm_back_link($this->u_action));
}
$template->assign_vars(array('REQUEST_CODE_FOR' => $user->lang('REQUEST_CODE_FOR', $config['whatsapp_sender']), 'S_EMPTY_SENDER' => empty($config['whatsapp_sender'])));
break;
}
}
示例6: upload_attachment
/**
* Upload Attachment - filedata is generated here
* Uses upload class
*
* @param string $form_name The form name of the file upload input
* @param int $forum_id The id of the forum
* @param bool $local Whether the file is local or not
* @param string $local_storage The path to the local file
* @param bool $is_message Whether it is a PM or not
* @param \filespec $local_filedata A filespec object created for the local file
* @param \phpbb\mimetype\guesser $mimetype_guesser The mimetype guesser object if used
* @param \phpbb\plupload\plupload $plupload The plupload object if one is being used
*
* @return object filespec
*/
function upload_attachment($form_name, $forum_id, $local = false, $local_storage = '', $is_message = false, $local_filedata = false, \phpbb\mimetype\guesser $mimetype_guesser = null, \phpbb\plupload\plupload $plupload = null)
{
global $auth, $user, $config, $db, $cache;
global $phpbb_root_path, $phpEx, $phpbb_dispatcher;
$filedata = array('error' => array());
include_once $phpbb_root_path . 'includes/functions_upload.' . $phpEx;
$upload = new fileupload();
if ($config['check_attachment_content'] && isset($config['mime_triggers'])) {
$upload->set_disallowed_content(explode('|', $config['mime_triggers']));
} else {
if (!$config['check_attachment_content']) {
$upload->set_disallowed_content(array());
}
}
$filedata['post_attach'] = $local || $upload->is_valid($form_name);
if (!$filedata['post_attach']) {
$filedata['error'][] = $user->lang['NO_UPLOAD_FORM_FOUND'];
return $filedata;
}
$extensions = $cache->obtain_attach_extensions($is_message ? false : (int) $forum_id);
$upload->set_allowed_extensions(array_keys($extensions['_allowed_']));
$file = $local ? $upload->local_upload($local_storage, $local_filedata, $mimetype_guesser) : $upload->form_upload($form_name, $mimetype_guesser, $plupload);
if ($file->init_error) {
$filedata['post_attach'] = false;
return $filedata;
}
// Whether the uploaded file is in the image category
$is_image = isset($extensions[$file->get('extension')]['display_cat']) ? $extensions[$file->get('extension')]['display_cat'] == ATTACHMENT_CATEGORY_IMAGE : false;
if (!$auth->acl_get('a_') && !$auth->acl_get('m_', $forum_id)) {
// Check Image Size, if it is an image
if ($is_image) {
$file->upload->set_allowed_dimensions(0, 0, $config['img_max_width'], $config['img_max_height']);
}
// Admins and mods are allowed to exceed the allowed filesize
if (!empty($extensions[$file->get('extension')]['max_filesize'])) {
$allowed_filesize = $extensions[$file->get('extension')]['max_filesize'];
} else {
$allowed_filesize = $is_message ? $config['max_filesize_pm'] : $config['max_filesize'];
}
$file->upload->set_max_filesize($allowed_filesize);
}
$file->clean_filename('unique', $user->data['user_id'] . '_');
// Are we uploading an image *and* this image being within the image category?
// Only then perform additional image checks.
$file->move_file($config['upload_path'], false, !$is_image);
// Do we have to create a thumbnail?
$filedata['thumbnail'] = $is_image && $config['img_create_thumbnail'] ? 1 : 0;
if (sizeof($file->error)) {
$file->remove();
$filedata['error'] = array_merge($filedata['error'], $file->error);
$filedata['post_attach'] = false;
return $filedata;
}
// Make sure the image category only holds valid images...
if ($is_image && !$file->is_image()) {
$file->remove();
if ($plupload && $plupload->is_active()) {
$plupload->emit_error(104, 'ATTACHED_IMAGE_NOT_IMAGE');
}
// If this error occurs a user tried to exploit an IE Bug by renaming extensions
// Since the image category is displaying content inline we need to catch this.
trigger_error($user->lang['ATTACHED_IMAGE_NOT_IMAGE']);
}
$filedata['filesize'] = $file->get('filesize');
$filedata['mimetype'] = $file->get('mimetype');
$filedata['extension'] = $file->get('extension');
$filedata['physical_filename'] = $file->get('realname');
$filedata['real_filename'] = $file->get('uploadname');
$filedata['filetime'] = time();
/**
* Event to modify uploaded file before submit to the post
*
* @event core.modify_uploaded_file
* @var array filedata Array containing uploaded file data
* @var bool is_image Flag indicating if the file is an image
* @since 3.1.0-RC3
*/
$vars = array('filedata', 'is_image');
extract($phpbb_dispatcher->trigger_event('core.modify_uploaded_file', compact($vars)));
// Check our complete quota
if ($config['attachment_quota']) {
if ($config['upload_dir_size'] + $file->get('filesize') > $config['attachment_quota']) {
$filedata['error'][] = $user->lang['ATTACH_QUOTA_REACHED'];
$filedata['post_attach'] = false;
$file->remove();
//.........这里部分代码省略.........
示例7: proceed_upload
/**
* 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;
}
示例8: fileupload
function upload_mod()
{
global $phpbb_root_path, $phpEx, $template, $user;
if (!isset($_POST['submit'])) {
return false;
}
if (check_form_key('acp_mods_upload') && isset($_FILES['modupload'])) {
$user->add_lang('posting');
// For error messages
include $phpbb_root_path . 'includes/functions_upload.' . $phpEx;
$upload = new fileupload();
// Only allow ZIP files
$upload->set_allowed_extensions(array('zip'));
// Let's make sure the mods directory exists and if it doesn't then create it
if (!is_dir($this->mods_dir)) {
mkdir($this->mods_dir, octdec($config['am_dir_perms']));
}
$file = $upload->form_upload('modupload');
if (empty($file->filename)) {
trigger_error($user->lang['NO_UPLOAD_FILE'] . adm_back_link($this->u_action), E_USER_WARNING);
} else {
if (!$file->init_error && !sizeof($file->error)) {
$file->clean_filename('real');
$file->move_file(str_replace($phpbb_root_path, '', $this->mods_dir), true, true);
if (!sizeof($file->error)) {
include $phpbb_root_path . 'includes/functions_compress.' . $phpEx;
$mod_dir = $this->mods_dir . '/' . str_replace('.zip', '', $file->get('realname'));
$compress = new compress_zip('r', $file->destination_file);
$compress->extract($mod_dir . '_tmp/');
$compress->close();
$folder_contents = scandir($mod_dir . '_tmp/', 1);
// This ensures dir is at index 0
// We need to check if there's a main directory inside the temp MOD directory
if (sizeof($folder_contents) == 3) {
// We need to move that directory then
$this->directory_move($mod_dir . '_tmp/' . $folder_contents[0], $this->mods_dir . '/' . $folder_contents[0]);
} else {
if (!is_dir($mod_dir)) {
// Change the name of the directory by moving to directory without _tmp in it
$this->directory_move($mod_dir . '_tmp/', $mod_dir);
}
}
$this->directory_delete($mod_dir . '_tmp/');
if (!sizeof($file->error)) {
$template->assign_vars(array('S_MOD_SUCCESSBOX' => true, 'MESSAGE' => $user->lang['MOD_UPLOAD_SUCCESS'], 'U_RETURN' => $this->u_action));
}
}
}
$file->remove();
if ($file->init_error || sizeof($file->error)) {
trigger_error((sizeof($file->error) ? implode('<br />', $file->error) : $user->lang['MOD_UPLOAD_INIT_FAIL']) . adm_back_link($this->u_action), E_USER_WARNING);
}
}
} else {
trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
}
return true;
}
示例9: time
/**
*
* @package automod
* @copyright (c) 2008 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
*
*/
function upload_ext($action)
{
global $phpbb_root_path, $phpEx, $phpbb_log, $phpbb_extension_manager, $template, $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
$upload_dir = $this->zip_dir;
// Make sure the ext/ directory exists and if it doesn't, create it
if (!is_dir($phpbb_root_path . 'ext')) {
$this->recursive_mkdir($phpbb_root_path . 'ext');
}
if (!is_writable($phpbb_root_path . 'ext')) {
$this->trigger_error($user->lang['EXT_NOT_WRITABLE'], E_USER_WARNING);
return false;
}
if (!is_dir($this->zip_dir)) {
$this->recursive_mkdir($this->zip_dir);
}
// Proceed with the upload
if ($action == 'upload') {
$file = $upload->form_upload('extupload');
} else {
if ($action == 'upload_remote') {
$file = $this->remote_upload($upload, $request->variable('remote_upload', ''));
} else {
if ($action == 'upload_from_phpbb') {
$file = $this->remote_upload($upload, $request->variable('valid_phpbb_ext', ''));
} else {
if ($action == 'upload_self') {
$this->self_update = $request->variable('self_update', '');
if ($this->self_update !== false && preg_match($this->phpbb_link_template, $this->self_update)) {
$file = $this->remote_upload($upload, $this->self_update);
} else {
$this->trigger_error($user->lang['EXT_UPLOAD_ERROR'], E_USER_WARNING);
return false;
}
}
}
}
}
// What is a safe limit of execution time? Half the max execution time should be safe.
$safe_time_limit = ini_get('max_execution_time') / 2;
$start_time = time();
// We skip working with a zip file if we are enabling/restarting the extension.
if ($action != 'force_update' && $action != 'upload_self_update') {
if ($action != 'upload_local') {
if (empty($file->filename)) {
$this->trigger_error(sizeof($file->error) ? implode('<br />', $file->error) : $user->lang['NO_UPLOAD_FILE'], E_USER_WARNING);
return false;
} else {
if ($file->init_error || sizeof($file->error)) {
$file->remove();
$this->trigger_error(sizeof($file->error) ? implode('<br />', $file->error) : $user->lang['EXT_UPLOAD_INIT_FAIL'], E_USER_WARNING);
return false;
}
}
$file->clean_filename('real');
$file->move_file(str_replace($phpbb_root_path, '', $upload_dir), true, true);
if (sizeof($file->error)) {
$file->remove();
$this->trigger_error(implode('<br />', $file->error), E_USER_WARNING);
return false;
}
$dest_file = $file->destination_file;
} else {
$dest_file = $upload_dir . '/' . $request->variable('local_upload', '');
}
if (!class_exists('\\compress_zip')) {
include $phpbb_root_path . 'includes/functions_compress.' . $phpEx;
}
// We need to use the user ID and the time to escape from problems with simultaneous uploads.
// We suppose that one user can upload only one extension per session.
$ext_tmp = 'tmp/' . (int) $user->data['user_id'];
// Ensure that we don't have any previous files in the working directory.
if (is_dir($phpbb_root_path . 'ext/' . $ext_tmp)) {
if (!$this->rrmdir($phpbb_root_path . 'ext/' . $ext_tmp)) {
if ($action != 'upload_local') {
$file->remove();
}
return false;
}
}
$zip = new \compress_zip('r', $dest_file);
$zip->extract($phpbb_root_path . 'ext/' . $ext_tmp . '/');
$zip->close();
$composery = $this->getComposer($phpbb_root_path . 'ext/' . $ext_tmp);
if (!$composery) {
//.........这里部分代码省略.........
示例10: time
/**
* 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 bool
*/
function upload_ext($action)
{
global $phpbb_root_path, $phpEx, $phpbb_log, $phpbb_extension_manager, $template, $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
$upload_dir = $phpbb_root_path . 'ext';
// Make sure the ext/ directory exists and if it doesn't, create it
if (!is_dir($phpbb_root_path . 'ext')) {
files::catch_errors(files::recursive_mkdir($phpbb_root_path . 'ext'));
}
if (!is_writable($phpbb_root_path . 'ext')) {
files::catch_errors($user->lang['EXT_NOT_WRITABLE']);
return false;
}
// Proceed with the upload
$file = files::remote_upload($upload, $request->variable('remote_upload', ''));
// What is a safe limit of execution time? Half the max execution time should be safe.
$safe_time_limit = ini_get('max_execution_time') / 2;
$start_time = time();
// We skip working with a zip file if we are enabling/restarting the extension.
if ($action != 'force_update') {
if (empty($file->filename)) {
files::catch_errors(sizeof($file->error) ? implode('<br />', $file->error) : $user->lang['NO_UPLOAD_FILE']);
return false;
} else {
if ($file->init_error || sizeof($file->error)) {
$file->remove();
files::catch_errors(sizeof($file->error) ? implode('<br />', $file->error) : $user->lang['EXT_UPLOAD_INIT_FAIL']);
return false;
}
}
$file->clean_filename('real');
$file->move_file(str_replace($phpbb_root_path, '', $upload_dir), true, true);
if (sizeof($file->error)) {
$file->remove();
files::catch_errors(implode('<br />', $file->error));
return false;
}
$dest_file = $file->destination_file;
if (!class_exists('\\compress_zip')) {
include $phpbb_root_path . 'includes/functions_compress.' . $phpEx;
}
// We need to use the user ID and the time to escape from problems with simultaneous uploads.
// We suppose that one user can upload only one extension per session.
$ext_tmp = $this->updater_ext_name . '/tmp/' . (int) $user->data['user_id'];
// Ensure that we don't have any previous files in the working directory.
if (is_dir($phpbb_root_path . 'ext/' . $ext_tmp)) {
if (!files::catch_errors(files::rrmdir($phpbb_root_path . 'ext/' . $ext_tmp))) {
$file->remove();
return false;
}
}
$zip = new \compress_zip('r', $dest_file);
$zip->extract($phpbb_root_path . 'ext/' . $ext_tmp . '/');
$zip->close();
$composery = files::getComposer($phpbb_root_path . 'ext/' . $ext_tmp);
if (!$composery) {
files::catch_errors(files::rrmdir($phpbb_root_path . 'ext/' . $ext_tmp));
$file->remove();
files::catch_errors($user->lang['ACP_UPLOAD_EXT_ERROR_COMP']);
return false;
}
$string = @file_get_contents($composery);
if ($string === false) {
files::catch_errors(files::rrmdir($phpbb_root_path . 'ext/' . $ext_tmp));
$file->remove();
files::catch_errors($user->lang['EXT_UPLOAD_ERROR']);
return false;
}
$json_a = json_decode($string, true);
$destination = isset($json_a['name']) ? $json_a['name'] : '';
$ext_version = isset($json_a['version']) ? $json_a['version'] : '0.0.0';
if (strpos($destination, '/') === false) {
files::catch_errors(files::rrmdir($phpbb_root_path . 'ext/' . $ext_tmp));
$file->remove();
files::catch_errors($user->lang['ACP_UPLOAD_EXT_ERROR_DEST']);
return false;
} else {
if (strpos($destination, objects::$upload_ext_name) === false) {
files::catch_errors(files::rrmdir($phpbb_root_path . 'ext/' . $ext_tmp));
$file->remove();
files::catch_errors($user->lang['ACP_UPLOAD_EXT_NOT_COMPATIBLE']);
return false;
//.........这里部分代码省略.........
示例11: upload_file
/**
* upload module zip
*/
private function upload_file()
{
global $user, $phpbb_root_path, $phpEx, $phpbb_admin_path, $template;
// Upload part
$user->add_lang('posting'); // For error messages
include($phpbb_root_path . 'includes/functions_upload.' . $phpEx);
$upload = new fileupload();
// Only allow ZIP files
$upload->set_allowed_extensions(array('zip'));
$file = $upload->form_upload('modupload');
// this is for module zips so don't allow anything else
if (empty($file->filename) || !preg_match('.zip.', $file->get('realname')))
{
trigger_error($user->lang['NO_FILE_B3P'] . adm_back_link($this->u_action), E_USER_WARNING);
}
else
{
if (!$file->init_error && !sizeof($file->error))
{
$file->clean_filename('real');
$file->move_file(str_replace($phpbb_root_path, '', $this->upload_path), true, true);
if (!sizeof($file->error))
{
include($phpbb_root_path . 'includes/functions_compress.' . $phpEx);
$mod_dir = $this->upload_path . str_replace('.zip', '', $file->get('realname'));
// make sure we don't already have the new folder
if(is_dir($mod_dir))
{
$this->directory_delete($mod_dir);
}
$compress = new compress_zip('r', $file->destination_file);
$compress->extract($mod_dir . '_tmp/');
$compress->close();
$folder_contents = $this->cut_folder(scandir($mod_dir . '_tmp/', 1)); // This ensures dir is at index 0
// We need to check if there's a main directory inside the temp MOD directory
if (sizeof($folder_contents) == 1)
{
// We need to move that directory then
$this->directory_move($mod_dir . '_tmp/' . $folder_contents[0], $this->upload_path . $folder_contents[0]);
$new_mod_dir = $this->upload_path . $folder_contents[0];
}
else if (!is_dir($mod_dir))
{
// Change the name of the directory by moving to directory without _tmp in it
$this->directory_move($mod_dir . '_tmp/', $mod_dir);
$new_mod_dir = $mod_dir;
}
$this->directory_delete($mod_dir . '_tmp/');
// make sure we set $mod_dir to the correct folder after the above step
$mod_dir = (isset($new_mod_dir)) ? $new_mod_dir : $mod_dir;
// if we got until here set $actions['NEW_FILES']
$actions['NEW_FILES'] = array();
// Now we need to get the files inside the folders
//$folder_contents = $this->cut_folder(scandir($mod_dir));
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($mod_dir)); // requires PHP 5
foreach($iterator as $cur_file)
{
$cur_path = $cur_file->getPathname();
$cur_path = str_replace('\\', '/', $cur_path); // we want unix-like paths
$cur_path = str_replace($mod_dir . '/', '', $cur_path);
$cut_pos = strpos($cur_path, '/');
/*
* We only copy files. The recursive iterator might grab paths depending on
* the PHP version. This will trigger our error handle with trigger_error()
* though. If we are trying to copy a directory just move on.
*/
if (is_dir($cur_path))
{
continue;
}
// Only allow files in adm, language, portal and styles folder and a license.txt
if(!in_array(substr($cur_path, 0, $cut_pos), array('adm', 'language', 'portal', 'styles')) && $cur_file->getFilename() != 'license.txt')
{
$file->remove();
$this->directory_delete($mod_dir);
trigger_error($user->lang['MODULE_CORRUPTED'] . adm_back_link(append_sid("{$phpbb_admin_path}index.$phpEx", 'i=portal&mode=modules')), E_USER_WARNING);
}
else
{
$actions['NEW_FILES'][$mod_dir . '/' . $cur_path] = $phpbb_root_path . $cur_path;
}
}
if (!sizeof($file->error))
//.........这里部分代码省略.........
示例12: strtolower
function upload_mod($action)
{
global $phpbb_root_path, $phpEx, $template, $user;
$can_upload = @ini_get('file_uploads') == '0' || strtolower(@ini_get('file_uploads')) == 'off' || !@extension_loaded('zlib') ? false : true;
// get FTP information if we need it
$hidden_ary = get_connection_info(false);
if (!isset($_FILES['modupload']) || $action != 'upload_mod') {
$template->assign_vars(array('S_FRONTEND' => true, 'S_MOD_UPLOAD' => $can_upload ? true : false, 'U_UPLOAD' => $this->u_action . '&action=upload_mod', 'S_FORM_ENCTYPE' => $can_upload ? ' enctype="multipart/form-data"' : '', 'S_HIDDEN_FIELDS' => build_hidden_fields($hidden_ary)));
add_form_key('acp_mods_upload');
return false;
}
// end pre_upload_mod
if (!check_form_key('acp_mods_upload')) {
trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
}
$user->add_lang('posting');
// For error messages
include $phpbb_root_path . 'includes/functions_upload.' . $phpEx;
$upload = new fileupload();
$upload->set_allowed_extensions(array('zip'));
// Only allow ZIP files
$write_method = 'editor_' . determine_write_method(false);
// For Direct & Manual write methods, make sure store/mods/ directory is writable
if ($write_method == 'editor_direct' || $write_method == 'editor_manual') {
if (!is_writable($this->mods_dir)) {
trigger_error($user->lang['MODS_NOT_WRITABLE'] . adm_back_link($this->u_action), E_USER_WARNING);
}
$write_method = 'editor_direct';
// Force Direct method, in the case of manual
$upload_dir = $this->mods_dir;
} else {
if (is_writable($this->store_dir)) {
$upload_dir = $this->store_dir;
} else {
trigger_error($user->lang['STORE_NOT_WRITABLE'] . adm_back_link($this->u_action), E_USER_WARNING);
}
}
$editor = new $write_method();
// Make sure the store/mods/ directory exists and if it doesn't, create it
if (!is_dir($this->mods_dir)) {
$editor->recursive_mkdir($this->mods_dir);
}
// Proceed with the upload
$file = $upload->form_upload('modupload');
if (empty($file->filename)) {
trigger_error($user->lang['NO_UPLOAD_FILE'] . adm_back_link($this->u_action), E_USER_WARNING);
} else {
if ($file->init_error || sizeof($file->error)) {
$file->remove();
trigger_error((sizeof($file->error) ? implode('<br />', $file->error) : $user->lang['MOD_UPLOAD_INIT_FAIL']) . adm_back_link($this->u_action), E_USER_WARNING);
}
}
$file->clean_filename('real');
$file->move_file(str_replace($phpbb_root_path, '', $upload_dir), true, true);
if (sizeof($file->error)) {
$file->remove();
trigger_error(implode('<br />', $file->error) . adm_back_link($this->u_action), E_USER_WARNING);
}
include $phpbb_root_path . 'includes/functions_compress.' . $phpEx;
$mod_dir = $upload_dir . '/' . str_replace('.zip', '', $file->get('realname'));
$compress = new compress_zip('r', $file->destination_file);
$compress->extract($mod_dir . '_tmp/');
$compress->close();
$folder_contents = scandir($mod_dir . '_tmp/', 1);
// This ensures dir is at index 0
$folder_contents = array_diff($folder_contents, array('.', '..'));
// We need to check if there's only one (main) directory inside the temp MOD directory
if (sizeof($folder_contents) == 1) {
$folder_contents = implode(null, $folder_contents);
$from_dir = $mod_dir . '_tmp/' . $folder_contents;
$to_dir = $this->mods_dir . '/' . $folder_contents;
} else {
if (!is_dir($mod_dir)) {
$from_dir = $mod_dir . '_tmp/';
$to_dir = $mod_dir . '/';
} else {
trigger_error($user->lang['MOD_UPLOAD_UNRECOGNIZED'] . adm_back_link($this->u_action), E_USER_WARNING);
}
}
// Copy that directory to the new path
$editor->copy_content($from_dir, $to_dir);
// Finally remove the main tmp extraction directory, directly, just like we created it
recursive_unlink($mod_dir . '_tmp/');
$template->assign_vars(array('S_MOD_SUCCESSBOX' => true, 'MESSAGE' => $user->lang['MOD_UPLOAD_SUCCESS'], 'U_RETURN' => $this->u_action));
// Remove the uploaded archive file
$file->remove();
return true;
}