function save($file) { if (!$file['hash']) { $file['hash'] = MD5(MD5($file['data']) . time()); } if (!$file['size']) { $file['size'] = strlen($file['data']); } $sql = 'INSERT INTO ' . FILE_TABLE . ' SET created=NOW() ' . ',type=' . db_input($file['type']) . ',size=' . db_input($file['size']) . ',name=' . db_input($file['name']) . ',hash=' . db_input($file['hash']); # XXX: ft does not exists during the upgrade when attachments are # migrated! if (isset($file['filetype'])) { $sql .= ',ft=' . db_input($file['filetype']); } if (!(db_query($sql) && ($id = db_insert_id()))) { return false; } $data = new AttachmentChunkedData($id); if (!$data->write($file['data'])) { return false; } return $id; }
function saveAttachment($file) { if(!$file['hash']) $file['hash']=MD5(md5_file($file['path']).time()); $file['data'] = file_get_contents($file['path']); if(!$file['size']) $file['size']=strlen($file['data']); $sql='INSERT INTO '.FILE_TABLE.' SET created=NOW() ' .',type='.db_input($file['type']) .',size='.db_input($file['size']) .',name='.db_input($file['name']) .',hash='.db_input($file['hash']); if (!(db_query($sql) && ($id=db_insert_id()))) return false; $f = new CompatAttachmentFile($id); $bk = new AttachmentChunkedData($f); if (!$bk->write($file['data'])) return false; return $id; }