Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Now getting following error when pressing upload image button:
- Unable to load the requested class: profileimages
- Upload Controller:
- <?php
- class Upload extends CI_Controller {
- function __construct()
- {
- parent::__construct();
- $this->load->model("profileimages");
- $this->load->helper(array('form', 'url'));
- }
- function index()
- {
- $this->load->view('upload_form', array('error' => ' ' ));
- }
- function Upload()
- {
- $user = $this->session->userdata('user');
- $this->profileimages->putProfileImage($user, $this->input->post("profileimage"));
- redirect('homeprofile/index');
- }
- function do_upload()
- {
- $config['upload_path'] = './uploads/';
- $config['allowed_types'] = 'gif|jpg|png';
- $config['max_size'] = '100';
- $config['max_width'] = '1024';
- $config['max_height'] = '768';
- $this->load->library('profileimages', $config);
- if (! $this->profileimages->do_upload())
- {
- $error = array('error'=>$this->profileimages->display_errors());
- $this->load->view('upload_form', $error);
- }
- else
- {
- $data = array('upload_data' => $this->profileimages->data());
- $this->load->view('upload_success', $data);
- }
- redirect('homeprofile/index');
- }
- function displayImage()
- {
- //Retrieve image id from the URI
- $imageid = $this->uri->segment(3);
- //Initialize the images model
- $this->load->model("profileimages");
- //Call the model's getImage function passing the image id
- $image = $this->image_model->getProfileImage($imageid);
- if (!is_null($image)) {
- //need to know the mine type
- // header('Content-Type: image/png');
- header ('Content-Type: image/jpg');
- imagejpeg(imagecreatefromstring($image), null,100);
- }
- else{
- // load a default profile image
- }
- function viewProfile(){
- //load profile detail view for users and display image
- // 18 = change to image id
- echo '<img src="<?=base_url()?>profile/displayImage/18" alt="profile"/>';
- }
- }
- }
- ?>
- ProfileImages Model:
- <?php
- class ProfileImages extends CI_Model
- {
- function ProfileImages()
- {
- parent::__construct();
- }
- function putProfileImage($user, $image)
- {
- $record = array('user' => $user, 'profileimage' => $image);
- if ($this->exists($user))
- {
- $this->db->update('profileimages', $record)->where('user', $user);
- }
- else
- {
- $this->db->insert('profileimages', $record);
- }
- }
- function getProfileImage($user)
- {
- $this->db->select('*')->from('profileimages')->where('user', $user);
- $query = $this->db->get();
- if ($query->num_rows() > 0){
- $row = $query->row();
- return $row->profileimage;
- }
- return Null;
- }
- }
- Homeprofile View:
- http://localhost/ci/web-project-jb.php/homeprofile
- <div id="maincontent">
- <div id="primary">
- <?$error;?>
- <?=form_open_multipart('upload/do_upload');?>
- <input type="file" name="userfile" size="20" />
- <?=form_submit('submit', 'Upload')?>
- <?=form_close();?>
- </div>
- <div id="secondary">
- <p>
- <?=$profileText;?>
- </p>
- <p>
- <?=form_open('homeprofile/changetext'); ?>
- <?php $msgbox = array(
- 'name' => 'profiletext',
- 'rows' => '8',
- 'cols' => '30',
- );?>
- <?=form_textarea($msgbox);?>
- </p>
- <p>
- <?=form_submit('submit', 'Change'); ?>
- <?=form_close(); ?>
- </p>
- </div>
- </div>
- Upload_success view:
- http://localhost/ci/web-project-jb.php/upload/do_upload
- I created this file following a tutorial, but ideally I want the image to appear on the same Homeprofile view page once uploaded
- <html>
- <head>
- <title>Upload Form</title>
- </head>
- <body>
- <h3>Your file was successfully uploaded!</h3>
- <ul>
- <?php foreach ($upload_data as $item => $value):?>
- <li><?php echo $item;?>: <?php echo $value;?></li>
- <?php endforeach; ?>
- </ul>
- <p><?php echo anchor('upload', 'Upload Another File!'); ?></p>
- </body>
- </html>
- SQL statement to create table - create table profileimages (user varchar(256),
- profileimage varchar(50));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement