image - creating profile pictures with codeigniter and tank auth -
i've tried following step step guide below tutorial upload failed : http://www.andrewrice.org/2012/03/creating-profile-pictures-with-codeigniter-and-tank-auth/
i have installed tank-auth codeigniter site. please tell me how fix issue. thank you.
**profile controller (/application/controllers/profile.php)** function picture() { /* loads tank auth "users" model, , assigns alias "foo" */ $this->load->model('tank_auth/users','foo'); /* gets logged-in user's id, preloaded tank auth library */ $user_id = $this->tank_auth->get_user_id(); /* queries profile information user who's logged in ... ... including profile pictures (see table structure below) */ $data = $this->foo->get_profile_by_id($user_id); /* passes data header, menu, form, , footer views */ $this->load->view('templates/header', $data); $this->load->view('templates/menu', $data); /* loads upload_form view */ $this->load->view('upload_form', array('error' => ' ' )); $this->load->view('templates/footer', $data); } } function do_upload() { /* upload settings */ $config['upload_path'] = './uploads/'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '1024'; $config['max_width'] = '1024'; $config['width'] = '128'; $config['max_height'] = '768'; /* encrypting helps prevent file name being discerned once saved */ $config['encrypt_name'] = 'true'; /* load codeigniter upload library, feed config above */ $this->load->library('upload', $config); /* checks if do_upload function has been executed ... ... , if not, shows upload form , errors (if exist) */ if (!$this->upload->do_upload()){ /* loads model (predefined database instructions, see below) ... ... , assigns nickname, went 'foo' */ $this->load->model('tank_auth/users','foo'); /* makes logged-in user's id nice, clean variable */ $user_id = $this->tank_auth->get_user_id(); /* use model gather user profile information user_id */ $profile_data = (array) $this->foo->get_profile_by_id($user_id); /* pass data data variable (for views) */ $data = $profile_data; /* process errors if exist */ $error = array('error' => $this->upload->display_errors()); /* pass views */ $this->load->view('templates/header', $data); $this->load->view('templates/menu', $data); $this->load->view('upload_form', $error); $this->load->view('templates/footer', $data); /* ... if file passes validation ... */ } else { /* load users model, assign alias 'foo' (or whatever want) */ $this->load->model('tank_auth/users','foo'); /* assign logged-in user id nice, clean variable */ $user_id = $this->tank_auth->get_user_id(); /* assign upload's metadata (size, dimensions, destination, etc.) ... ... array nice, clean variable */ $upload = (array) $this->upload->data(); /* assign's user's profile data yet nice, clean variable */ $profile_data = (array) $this->foo->get_profile_by_id($user_id); /* uses 2 upload library features assemble file name (the name, , extension) */ $filename = $upload['raw_name'].$upload['file_ext']; /* same thumbnail we'll generate, suffix '_thumb' */ $thumb = $upload['raw_name']."_thumb".$upload['file_ext']; /* set rules upload */ $config['image_library'] = 'gd2'; $config['source_image'] = "./uploads/".$filename; $config['create_thumb'] = true; $config['maintain_ratio'] = true; $config['width'] = 128; $config['height'] = 128; /* load "image manipulation library", see codeigniter user guide */ $this->load->library('image_lib', $config); /* resize image! */ $this->image_lib->resize(); /* assign upload_data $data variable */ $data['upload_data'] = $this->upload->data(); /* assign profile_data $data variable */ $data['profile_data'] = $profile_data; /* runs users model (update_photo function, see below) , ... ... loads location of photo new photo user's profile */ $this->foo->update_photo($user_id, $filename, $thumb); /* load "success" view data! */ $this->load->view('upload_success', $data); } } **the upload form view (/application/views/upload_form.php)** <h1>change profile picture</h1> <?php echo $error;?> <?php echo form_open_multipart('profile/do_upload');?> <input type="file" name="userfile" size="20" /> <input type="submit" value="upload new picture" />undefined</form> **user model (/application/models/tank_auth/users.php)** function update_photo($user_id, $filename, $thumb){ $this->db->where('user_id', $user_id); $arr = array( 'photo'=> $filename, 'thumb' => $thumb ); $this->db->update($this->profile_table_name, $arr); } **displaying profile picture (/application/views/menu.php)** <div style='width: 128px; height: <?php echo $size[1]; ?>px; margin-bottom: 10px; border: solid 1px #ccc; background: url("http://thc.fiu.edu/uploads/ <?php echo $thumb; ?>");'/> <?php $size = getimagesize("http://www.yourwebsite.com/uploads/".$thumb); ?> <a href="/profile/picture" class='editprofile' style="display: block; width: 128px; height: <?php echo $size[1]; ?>px"> </a> </div>
Comments
Post a Comment