Matteus Posted November 5, 2020 Report Share Posted November 5, 2020 On 11/3/2020 at 6:09 PM, Kami said: Вы напишите что у вас на 251 строчке, и желательно в разрезе всей функции к которой эта строка относится. Там, собственно этот код. Я у себя в начале добавил еще проверку if($files) $files = array(); $files = (array)$this->request->post('files'); // Удаление файлов $current_files = $this->files->get_files(array('object_id'=>$product->id,'type'=>'product')); foreach($current_files as $file) if(!in_array($file->id, $files['id'])) // и вот здесь, когда все файлы удаляешь - возникает ошибка in_array() expects parameter 2 to be array т.к. $files пустой. $this->files->delete_file($file->id); Quote Link to post Share on other sites
phukortsin Posted November 5, 2020 Report Share Posted November 5, 2020 (edited) Пробуйте if(!is_array($files['id']) || !in_array($file->id, $files['id'])) Edited November 5, 2020 by phukortsin Quote Link to post Share on other sites
Matteus Posted November 5, 2020 Report Share Posted November 5, 2020 Так выглядит намного лучше) И работает! Quote Link to post Share on other sites
get31 Posted May 11, 2021 Report Share Posted May 11, 2021 В 30.10.2017 в 09:03, miltonmors сказал: А что ж Вы тогда хотите? Плагин применяется к пустому значению, и показывает 0, т.е. плагин отрабатывает нормально. Выходит, у Вас ошибка еще ДО применения плагина. $filename.size - выглядит как чистая бессмыслица. Проверить плагин отдельно можно так {3544|filesize} {32987500|filesize} Пробуйте примерно так: {assign var=fn value="`$config->cms_files_dir``$file->filename`"} {filesize($fn)|filesize} Подскажите, пожалуйста, как вывести вес изображения? {$product->images[0]->filename|resize:800:600} Делаю: {assign var=fn value="{$product->images[0]->filename|resize:800:600}"} {filesize($fn)|filesize} и результата ноль :(( Quote Link to post Share on other sites
phukortsin Posted May 12, 2021 Report Share Posted May 12, 2021 1. В переменной $fn получается значение вида http://domain.com/files/products/dc23_pink_weis_klein.800x600.jpeg?e420333638500a52e02ba1a9a3508938 А надо формировать в виде files/products/dc23_pink_weis_klein.800x600.jpeg 2. Надо использовать {filesize($fn)} или {$fn|filesize} Quote Link to post Share on other sites
get31 Posted May 12, 2021 Report Share Posted May 12, 2021 5 часов назад, phukortsin сказал: 1. В переменной $fn получается значение вида http://domain.com/files/products/dc23_pink_weis_klein.800x600.jpeg?e420333638500a52e02ba1a9a3508938 А надо формировать в виде files/products/dc23_pink_weis_klein.800x600.jpeg 2. Надо использовать {filesize($fn)} или {$fn|filesize} {$product->images[0]->filename|resize:800:600} уже формирует с http://domain.com/ , а как убрать домен и оставить только files/products/name.800x600.jpg? Quote Link to post Share on other sites
get31 Posted May 13, 2021 Report Share Posted May 13, 2021 В 12.05.2021 в 13:16, get31 сказал: {$product->images[0]->filename|resize:800:600} уже формирует с http://domain.com/ , а как убрать домен и оставить только files/products/name.800x600.jpg? Вообщем сделал так: {$product->images[0]->filename|resize:800:600|regex_replace:"'.*\://site.com/'"} Quote Link to post Share on other sites
DarkRaveN Posted June 18, 2021 Report Share Posted June 18, 2021 (edited) Кто-нибудь может перезалить архив? Все архивы битые. Заранее спасибо! Edited June 18, 2021 by DarkRaveN Quote Link to post Share on other sites
DarkRaveN Posted June 21, 2021 Report Share Posted June 21, 2021 (edited) Файл найден, спасибо get31! Если кому еще нужен https://disk.yandex.ru/d/usm93O0SLxZoWQ Edited June 21, 2021 by DarkRaveN Quote Link to post Share on other sites
6cnitymi Posted March 13, 2024 Report Share Posted March 13, 2024 В 21.06.2021 в 09:05, DarkRaveN сказал: Файл найден, спасибо get31! Если кому еще нужен https://disk.yandex.ru/d/usm93O0SLxZoWQ Добрый день! Есть у кого-нибудь возможность залить повторно? Или выложить содержимое файла Files.php? Спасибо! Quote Link to post Share on other sites
get31 Posted April 16, 2024 Report Share Posted April 16, 2024 В 13.03.2024 в 08:32, 6cnitymi сказал: Добрый день! Есть у кого-нибудь возможность залить повторно? Или выложить содержимое файла Files.php? Спасибо! <?php require_once('Simpla.php'); class Files extends Simpla { private $allowed_extentions = array('pdf', 'txt', 'doc', 'docx', 'xls', 'xlsx', 'mp4', 'mp3', 'psd', 'ai', 'zip', 'rar'); public function __construct() { parent::__construct(); } function get_files($filter = array()) { $object_id_filter = ''; $type_filter = ''; if(!empty($filter['object_id'])) $object_id_filter = $this->db->placehold('AND f.object_id in(?@)', (array)$filter['object_id']); if(!empty($filter['type'])) $type_filter = $this->db->placehold('AND f.type=?', $filter['type']); // files $query = $this->db->placehold("SELECT f.id, f.name, f.object_id, f.filename, f.type, f.position FROM __files AS f WHERE 1 $object_id_filter $type_filter ORDER BY f.object_id, f.position"); $this->db->query($query); return $this->db->results(); } public function add_file($object_id, $type, $filename, $name = '') { $query = $this->db->placehold("SELECT id FROM __files WHERE object_id=? AND type=? AND filename=?", $object_id, $type, $filename); $this->db->query($query); $id = $this->db->result('id'); if(empty($id)) { $query = $this->db->placehold("INSERT INTO __files SET object_id=?, type=?, filename=?", $object_id, $type, $filename); $this->db->query($query); $id = $this->db->insert_id(); $query = $this->db->placehold("UPDATE __files SET position=id WHERE id=?", $id); $this->db->query($query); } return($id); } public function update_file($id, $file) { $query = $this->db->placehold("UPDATE __files SET ?% WHERE id=?", $file, $id); $this->db->query($query); return($id); } public function delete_file($id) { $query = $this->db->placehold("SELECT filename FROM __files WHERE id=?", $id); $this->db->query($query); $filename = $this->db->result('filename'); $query = $this->db->placehold("DELETE FROM __files WHERE id=? LIMIT 1", $id); $this->db->query($query); $query = $this->db->placehold("SELECT count(*) as count FROM __files WHERE filename=? LIMIT 1", $filename); $this->db->query($query); $count = $this->db->result('count'); if($count == 0) { $file = pathinfo($filename, PATHINFO_FILENAME); $ext = pathinfo($filename, PATHINFO_EXTENSION); @unlink($this->config->root_dir.$this->config->cms_files_dir.$filename); } } public function upload_file($filename, $name) { // Имя оригинального файла $name = $this->correct_filename($name); $uploaded_file = $new_name = pathinfo($name, PATHINFO_BASENAME); $base = pathinfo($uploaded_file, PATHINFO_FILENAME); $ext = pathinfo($uploaded_file, PATHINFO_EXTENSION); if(in_array(strtolower($ext), $this->allowed_extentions)) { while(file_exists($this->config->root_dir.$this->config->cms_files_dir.$new_name)) { $new_base = pathinfo($new_name, PATHINFO_FILENAME); if(preg_match('/_([0-9]+)$/', $new_base, $parts)) $new_name = $base.'_'.($parts[1]+1).'.'.$ext; else $new_name = $base.'_1.'.$ext; } if(move_uploaded_file($filename, $this->config->root_dir.$this->config->cms_files_dir.$new_name)) return $new_name; } return false; } public function correct_filename($filename) { $ru = explode('-', "А-а-Б-б-В-в-Ґ-ґ-Г-г-Д-д-Е-е-Ё-ё-Є-є-Ж-ж-З-з-И-и-І-і-Ї-ї-Й-й-К-к-Л-л-М-м-Н-н-О-о-П-п-Р-р-С-с-Т-т-У-у-Ф-ф-Х-х-Ц-ц-Ч-ч-Ш-ш-Щ-щ-Ъ-ъ-Ы-ы-Ь-ь-Э-э-Ю-ю-Я-я"); $en = explode('-', "A-a-B-b-V-v-G-g-G-g-D-d-E-e-E-e-E-e-ZH-zh-Z-z-I-i-I-i-I-i-J-j-K-k-L-l-M-m-N-n-O-o-P-p-R-r-S-s-T-t-U-u-F-f-H-h-TS-ts-CH-ch-SH-sh-SCH-sch---Y-y---E-e-YU-yu-YA-ya"); $res = str_replace($ru, $en, $filename); $res = preg_replace("/[\s]+/ui", '-', $res); $res = preg_replace("/[^a-zA-Z0-9\.\-\_]+/ui", '', $res); $res = strtolower($res); return $res; } } Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.