<?php _::define_controller('download', function () { _::declare_component('file'); // force download uploads/file.php $file = new file('uploads/', 'file.php'); $file->download(); }); _::define_controller('upload', function () { _::declare_component('file'); // for upload: $file = new file(); $location = $file->upload('FIELD', 'uploads/', true, true, array('jpg', 'jpeg', 'png', 'gif')); });
/** * Forces a download of a created archive. * * @param string name of the file that will be downloaded * @return void */ public function download($filename) { file::download($filename, $this->driver->create($this->paths)); }
protected function _image_link($gallery) { if (request::is_ajax()) { $this->_use_json_errors(); } if ($gallery->id == 0) { return View::global_error('Invalid Gallery id'); } if (isset($_POST['username']) && isset($_POST['password'])) { Auth::instance()->login($_POST['username'], $_POST['password']); } if (!Auth::instance()->logged_in('login')) { return View::global_error('Image upload requires login'); } if ($gallery->user_id != 0 && $gallery->user_id != Auth::instance()->get_user()->id) { return View::global_error('User not gallery owner'); } if ($this->input->post('name') == '') { View::global_error('Missing Image Name'); } if ($this->input->post('file') == '') { View::global_error('Missing File Name'); } if (View::errors_set()) { return; } $tmp = file::download($_POST['file']); $image = ORM::factory('image'); $image->gallery_id = $gallery->id; $image->name = $this->input->post('name'); $image->mime = file::mime($tmp); $image->description = isset($_POST['description']) ? $_POST['description'] : $_POST['file']; $image->size = filesize($tmp); $image->uploaded_on = time(); $image->uploaded_by = Auth::instance()->get_user()->id; if (!$image->validate()) { return View::global_error('Error validating Image'); } if (!$image->replace_uploaded_file($tmp)) { return View::global_error('Error moving Image'); } if (!$image->save()) { return View::global_error('Error saving Image'); } if (!$image->generate_thumb()) { return View::global_error('Error generating thumb'); } $_POST = array(); if (request::is_ajax()) { die(json_encode(array('result' => 'OK', 'id' => $image->id, 'name' => $image->name, 'url' => $image->generate_url()))); } }