diff options
author | Bharat Mediratta <bharat@menalto.com> | 2008-11-10 12:28:58 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2008-11-10 12:28:58 +0000 |
commit | ceb07822339d92e399b3c93069ff356fcc68a278 (patch) | |
tree | f74ee5f31d807c2732c196a646a4ec91c3a48e4f /core | |
parent | aceb0309731f94813eaefa9e34cd0253425c6151 (diff) |
Add support for multi-file-upload using jquery.MultiFile and modify
Item_Controller to accept it.
Diffstat (limited to 'core')
-rw-r--r-- | core/controllers/item.php | 35 | ||||
-rw-r--r-- | core/views/welcome.html.php | 29 |
2 files changed, 47 insertions, 17 deletions
diff --git a/core/controllers/item.php b/core/controllers/item.php index 38049380..d2986cc7 100644 --- a/core/controllers/item.php +++ b/core/controllers/item.php @@ -66,25 +66,40 @@ class Item_Controller extends Controller { switch ($this->input->post("type")) { case "album": - $new_item = album::create( + $album = album::create( $item->id, $this->input->post("name"), $this->input->post("title", $this->input->post("name")), $this->input->post("description")); + url::redirect("album/{$album->id}"); break; case "photo": - $new_item = photo::create( - $item->id, - $_FILES["file"]["tmp_name"], - $_FILES["file"]["name"], - $this->input->post("title", $this->input->post("name")), - $this->input->post("description")); + if (is_array($_FILES["file"]["name"])) { + for ($i = 0; $i < count($_FILES["file"]["name"]); $i++) { + if ($_FILES["file"]["error"][$i] == 0) { + $photo = photo::create( + $item->id, + $_FILES["file"]["tmp_name"][$i], + $_FILES["file"]["name"][$i], + $_FILES["file"]["name"][$i]); + } else { + print "ERROR!"; + // @todo return a reasonable error + } + } + url::redirect("album/{$item->id}"); + } else { + $photo = photo::create( + $item->id, + $_FILES["file"]["tmp_name"], + $_FILES["file"]["name"], + $this->input->post("title", $this->input->post("name")), + $this->input->post("description")); + url::redirect("{$new_item->type}/{$new_item->id}"); + } break; } - - print url::redirect("{$new_item->type}/{$new_item->id}"); - return; } public function delete($item) { diff --git a/core/views/welcome.html.php b/core/views/welcome.html.php index 830539a9..bf7ba455 100644 --- a/core/views/welcome.html.php +++ b/core/views/welcome.html.php @@ -97,9 +97,19 @@ margin-left: 1em; padding-bottom: 0; } + + div#photo_upload_wrap { + display: inline; + } + + div#photo_upload_wrap { + display: inline; + } + </style> - <script type="text/javascript" src="<?= url::base() . "lib/jquery.js" ?>"></script> - <script type="text/javascript" src="<?= url::base() . "lib/jquery.cookie.js" ?>"></script> + <script type="text/javascript" src="<?= url::file("lib/jquery.js") ?>"></script> + <script type="text/javascript" src="<?= url::file("lib/jquery.cookie.js") ?>"></script> + <script type="text/javascript" src="<?= url::file("lib/jquery.MultiFile.js") ?>"></script> </head> <body> <div class="outer"> @@ -129,8 +139,12 @@ <div id="activities"> <script> show = function(section) { + var section_id = "#" + section; + if ($(section_id).css("display") == "block") { + return; + } $("div.activity").slideUp(); - $("#" + section).slideDown(); + $(section_id).slideDown(); $.cookie("active_section", section); } $(document).ready(function(){ @@ -138,7 +152,8 @@ if (!active_section) { active_section = 'config'; } - $("#" + active_section).show() + $("#" + active_section).show(); + $("#photo_upload").MultiFile(); }); </script> @@ -161,19 +176,19 @@ <fieldset> <legend>Photos</legend> <form method="post" action="<?= url::site("album/1") ?>" enctype="multipart/form-data"> - <input name="file" type="file"/> + <input type="submit" value="upload"/> + <input id="photo_upload" name="file[]" type="file"/> <input type="hidden" name="type" value="photo"/> <input type="hidden" name="__action" value="put"/> - <input type="submit" value="upload"/> </form> </fieldset> <fieldset> <legend>Albums</legend> <form method="post" action="<?= url::site("album/1") ?>"> + <input type="submit" value="create"/> <input type="text" name="name"/> <input type="hidden" name="type" value="album"/> <input type="hidden" name="__action" value="put"/> - <input type="submit" value="create"/> </form> </fieldset> </div> |