/** * Sync attachments */ public function attachments($mode, $attachment_id = false) { switch ($mode) { case 'hash': $sql = 'SELECT * FROM ' . $this->attachments_table . ($attachment_id !== false ? 'WHERE attachment_id = ' . (int) $attachment_id : ''); $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $this->attachment->__set_array($row); $file = $this->attachment->get_filepath(); if (file_exists($file)) { $md5 = md5_file($file); if ($md5 != $row['hash']) { $sql = 'UPDATE ' . $this->attachments_table . ' SET hash = "' . $this->db->sql_escape($md5) . '" WHERE attachment_id = ' . $row['attachment_id']; $this->db->sql_query($sql); } } } $this->db->sql_freeresult($result); break; } }