From af700ea27703bbec5aa1078a84f9fd44c0260322 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Tue, 26 May 2009 21:20:04 -0400 Subject: Let's you upload a file with a notice and have it shown with other attachments. --- actions/newnotice.php | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'actions/newnotice.php') diff --git a/actions/newnotice.php b/actions/newnotice.php index ae0ff9636..d7507c118 100644 --- a/actions/newnotice.php +++ b/actions/newnotice.php @@ -109,6 +109,10 @@ class NewnoticeAction extends Action } } + function isFileAttached() { + return $_FILES['attach']['error'] === UPLOAD_ERR_OK; + } + /** * Save a new notice, based on arguments * @@ -158,7 +162,6 @@ class NewnoticeAction extends Action $replyto = 'false'; } -// $notice = Notice::saveNew($user->id, $content_shortened, 'web', 1, $notice = Notice::saveNew($user->id, $content_shortened, 'web', 1, ($replyto == 'false') ? null : $replyto); @@ -167,6 +170,9 @@ class NewnoticeAction extends Action return; } + if ($this->isFileAttached()) { + $this->storeFile($notice); + } $this->saveUrls($notice); common_broadcast_notice($notice); @@ -194,6 +200,33 @@ class NewnoticeAction extends Action } } + function storeFile($notice) { + $filename = basename($_FILES['attach']['name']); + $destination = "file/{$notice->id}-$filename"; + if (move_uploaded_file($_FILES['attach']['tmp_name'], INSTALLDIR . "/$destination")) { + $file = new File; +// $file->url = common_local_url('file', array('notice' => $notice->id)); + $file->url = common_path($destination); + $file->size = filesize(INSTALLDIR . "/$destination"); + $file->date = time(); + $file->mimetype = $_FILES['attach']['type']; + if ($ok = $file->insert()) { + $f2p = new File_to_post; + $f2p->file_id = $ok; + $f2p->post_id = $notice->id; + $f2p->insert(); + } else { + die('inserting file, dying'); + } + } +/* + $url = common_local_url('file', array('notice' => $notice->id)); + echo "$destination
"; + die($url); +*/ + } + + /** save all urls in the notice to the db * * follow redirects and save all available file information @@ -203,7 +236,7 @@ class NewnoticeAction extends Action * * @return void */ - function saveUrls($notice) { + function saveUrls($notice, $uploaded = null) { common_replace_urls_callback($notice->content, array($this, 'saveUrl'), $notice->id); } -- cgit v1.2.3-54-g00ecf