public function post() { $data['message1'] = ""; $data['message2'] = ""; $data['message'] = ""; $this->form_validation->set_rules('post_data', 'Post data', 'trim|required|max_length[800]|xxs_clean'); if ($this->form_validation->run() == TRUE) { $post = new Post_info(); $post->user_id = $this->session->userdata('user_id'); $post->post_data = $this->input->post('post_data'); $postObj = $post->addPost(); if (isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") { foreach ($_FILES['files']['name'] as $f => $name) { /* adding database information for image */ $imageData = new Image_info(); $imageData->user_id = $this->session->userdata('user_id'); $imageData->image_type = "post"; $imageData->id = $postObj->post_id; $imageObj = $imageData->addImage(); /* uploading file on server file system */ $valid_formats = array("jpg", "jpeg", "png", "gif", "bmp"); $max_file_size = 1024 * 1024; //1 mb $path = "assets/sns_img"; $count = 0; $ImageName = $path . "/" . $imageObj->image_id; if ($_FILES['files']['error'][$f] == 4) { continue; // Skip file if any error found } if ($_FILES['files']['error'][$f] == 0) { if ($_FILES['files']['size'][$f] > $max_file_size) { $data['message1'] = "File too large"; continue; // Skip large files } elseif (!in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats)) { $data['message1'] = $data['message1'] . " File extension unsupported"; continue; // Skip invalid file formats } else { // No error found! Move uploaded files if (move_uploaded_file($_FILES["files"]["tmp_name"][$f], $ImageName)) { $count++; // Number of successfully uploaded file $data['message1'] = "posted successful"; } } } } } $url = base_url() . "user/index/" . $data['message1']; redirect($url, 'Location'); } }
<div class="full col-sm-9"> <!-- main col left --> <div class="col-sm-8"> <?php foreach ($wda as $o) { ?> <!-- All status upadtes on wall --> <div class="panel panel-default"> <?php $done = "shared"; $time = $o->post_time; $images = Image_info::getImages("post", $o->post_id); $val = "false"; if ($o->user_id == $this->session->userdata('user_id')) { $val = "true"; } ?> <div class="panel-heading"><?php if ($val == "true") { ?> <a href="#" class="pull-right">Delete</a> <?php } ?> <h4><?php echo $o->first_name . " " . $o->last_name . " " . $done . " on " . $time; ?> </h4></div>
public function getImages($type, $id) { $query = "select * from image_info where image_type='" . $type . "' and id = " . $id; $records = $this->db->query($query); return Image_info::instantiate($records); }