public function add($name, $type, $size, $path) { $tbl = new Media_Table(); $tbl->name($name)->type($type)->size($size)->path($path); $tbl->datetime_create = date("Y-m-d H:i:s"); if (!$tbl->save()) { throw new Core_Db_Table_Exception(); } return $tbl; }
public function uploadAction() { $this->view->disable(); $name = $_FILES['media']['name']; $type = $_FILES['media']['type']; $tmpName = $_FILES['media']['tmp_name']; $size = $_FILES['media']['size']; $cfg = new Phalcon\Config\Adapter\Ini('../app/Config/config.ini'); $hashName = hash_file('md5', $tmpName); $path = $cfg->media->path . '/' . $hashName; $pathFull = getcwd() . $path; if (file_exists($pathFull)) { echo json_encode(Media_Table::findFirst("path = '{$path}'")->toArray()); return; } if (!move_uploaded_file($tmpName, $pathFull)) { return; } $row = Core_Media_Manager::getInstance()->add($name, $type, $size, $path); echo json_encode($row->toArray()); }