public function uploadImage($file) { if (!isset($file['error']) || $file['error']['image'] === 0) { preg_match('/image\\/(\\w+)/s', $file['type']['image'], $ext); $uploadPath = Application::getParam('uploadPath') . "/" . strtolower(get_called_class()) . "/"; $file_name = time() . ".{$ext[1]}"; $target_file = $uploadPath . $file_name; if (!move_uploaded_file($file["tmp_name"]["image"], $target_file)) { //TODO: Will do exception die("File is not uploaded"); } return $file_name; } }
public function get($__get) { if (!isset($__get['page'])) { $this->controller = Application::getParam('defaultController') . "Controller"; } else { $this->controller = $__get['page'] . "Controller"; } if (!isset($__get['action'])) { $this->action = 'index'; } else { $this->action = $__get['action']; } $class = ucfirst($this->controller); $file = __DIR__ . "/../controllers/" . $class . ".php"; if (file_exists($file)) { require_once $file; $controller = new $class(); $controller->{$this->action}(); } else { throw new Exception("File not exist!"); } }
echo !empty($post->id) ? '<input name="Post[post_id]" type="hidden" value="' . $post->id . '"' : null; ?> <label for="title">Title:</label> <div class="post-title-block"><input value="<?php echo $post->title; ?> " id="title" name="Post[title]" class="post-title" type="text"></div> <label for="image">Image:</label> <div class="post-file-block"> <?php if (!empty($post->image)) { ?> <div><img src="<?php echo Application::getParam('basePath'); ?> uploads/post/<?php echo $post->image; ?> " /></div> <br/> <?php } ?> <input id="image" name="Post[image]" type="file"/> </div> <label for="status">Status:</label> <div class="post-status-block">
public function __construct() { $dbconf = Application::getParam('database'); $this->connection = new PDO("mysql:host={$dbconf['host']};dbname={$dbconf['dbname']}", $dbconf['user'], $dbconf['password']); $this->connection->exec('set names utf8'); }