function posts($num) { $posts = $this->random_titles($num); $images = $this->random_images($num); $this->db->select('user_id'); $this->db->distinct(); $this->db->from('user'); $this->db->order_by('user_id', 'random'); $this->db->limit($num); $result = $this->db->get(); $users = $result->result_array(); for ($i = 0; $i < $num; $i++) { $user_id = $users[$i]['user_id']; $post_text = $posts[$i]; $post_title = $posts[$i]; $post_tags = str_replace(' ', ',', $posts[$i]); $image = $images[$i]; $imagedata['image_palette'] = json_encode(getImageColorPalette($this->config->item('app_path') . '/data/test/' . $image)); $data = array('post_text' => $post_text, 'post_title' => $post_title, 'post_user_id' => $user_id); //var_dump($data); // var_dump($post_tags); // var_dump($image); $this->db->trans_begin(); if (!$this->db->insert('post', $data)) { $result->error = 'Error while writing tribble data.'; var_dump($result); } $post_id = $this->db->insert_id(); $tagdata['tag_content'] = $post_tags; $tagdata['tag_post_id'] = $post_id; if (!$this->db->insert('tag', $tagdata)) { $result->error = 'Error while writing tag data.'; var_dump($result); } $imagedata['image_post_id'] = $post_id; $imagedata['image_path'] = '/data/tests/' . $image; if (!$this->db->insert('image', $imagedata)) { $result->error = 'Error while writing image data.'; var_dump($result); } $likedata['like_post_id'] = $post_id; $likedata['like_user_id'] = $user_id; if (!$this->db->insert('like', $likedata)) { $result->error = "Error while writing like data"; var_dump($result); } $this->db->trans_complete(); echo "Post (" . $post_id . ") was inserted<br>"; } }
public function upload() { if (!$this->session->userdata('unique')) { redirect('/user/login'); } else { // check if the form was posted if (isset($_POST['createTribble'])) { // get the uid from the session data and hash it to be used as the user upload folder name $user_hash = do_hash($this->session->userdata('unique')); // load the tribble model $this->load->model('Tribbles_model', 'trModel'); // set the upload configuration $ulConfig['upload_path'] = './data/' . $user_hash . '/'; $ulConfig['allowed_types'] = 'jpg|png'; $ulConfig['max_width'] = '400'; $ulConfig['max_height'] = '300'; // load the file uploading lib and initialize $this->load->library('upload', $ulConfig); $this->upload->initialize($ulConfig); // check if upload was successful and react if (!$this->upload->do_upload('image')) { $error = array('error' => $this->upload->display_errors()); } else { $data = array('upload_data' => $this->upload->data()); // set the data to write in db; $imgdata = array('image_path' => substr($ulConfig['upload_path'] . $data['upload_data']['file_name'], 1), 'image_palette' => json_encode(getImageColorPalette($data['upload_data']['full_path']))); $config['image_library'] = 'gd2'; $config['source_image'] = $ulConfig['upload_path'] . $data['upload_data']['file_name']; $config['create_thumb'] = TRUE; $config['maintain_ratio'] = TRUE; $config['width'] = 200; $config['height'] = 150; $this->load->library('image_lib', $config); $this->image_lib->resize(); if (!($result = $this->trModel->createNewTribble($imgdata))) { $data['error'] = $result->error; } else { $data['success'] = "YAY!"; } } } $data['title'] = 'Tribble - Upload'; $data['meta_description'] = 'A design content sharing and discussion tool.'; $data['meta_keywords'] = 'Tribble'; $this->load->view('common/page_start.php', $data); $this->load->view('common/top_navigation.php', $data); $this->load->view('tribbles/upload.php', $data); $this->load->view('common/page_end.php', $data); } }