Все-равно .... или PHP Fatal error: Uncaught Error: Call to a member function sql_build_array() on null in или окошко HTTP error ... (((
Может что-то упустил-пропустил?
Код: Выделить всё
<?php
namespace vlad\image_convert\event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Event listener
*/
class listener implements EventSubscriberInterface
{
/**
* Assign functions defined in this class to event listeners in the core
*
* @return array
* @static
* @access public
*/
static public function getSubscribedEvents()
{
return array(
'core.modify_uploaded_file' => array ('upload_image_convert', 1),
);
}
/** @var \phpbb\config\config */
protected $config;
//** @var string phpbb_root_path */
protected $phpbb_root_path;
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/**
* Constructor
*/
public function __construct(
$phpbb_root_path,
\phpbb\config\config $config,
\phpbb\db\driver\driver_interface $db
)
{
$this->db = $db;
$this->phpbb_root_path = $phpbb_root_path;
$this->config = $config;
}
public function upload_image_convert($event)
{
$is_image = $event['is_image'];
$filedata = $event['filedata'];
$destination_file = $this->phpbb_root_path . $this->config['upload_path'] . '/' . $filedata['physical_filename'];
if ($is_image)
{
if (function_exists('exif_imagetype') && ($filedata['extension'] == 'png'))
{
$sql_data = array(
'real_filename' => $filedata['physical_filename'],
'extension ' => $filedata['extension'],
);
$sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_data) . ' WHERE attach_id = ' . $filedata['attach_id'];
$this->db->sql_query($sql);
}
}
}
}
Отправлено спустя 17 минут 40 секунд:
Sheer писал(а): 09.09.2017 17:03Ни до, ни во время, физически невозможно.
Я имею ввиду в момент когда файл загружается в папку files в виде набора символов, а в бд первый раз прописываются имя файла и расширение, тут и поменять png на jpg. Или для этого нет события ядра, чтобы прикрутить функцию?