Welcome Guest, Not a member yet? Register   Sign In
I am uploading a profile image into a database but they do not upload into my uploads folder
#1

[eluser]James_B[/eluser]
This was working for me at one stage, until when I was changing other parts of my code and it decided not to upload to my images folder any longer.

Here is my controller:
Code:
<?php
class HomeProfile extends CI_Controller
{


  function HomeProfile()
  {
    parent::__construct();
    $this->load->model("profiles");
    $this->load->model("profileimages");
    $this->load->helper(array('form', 'url'));
  }

  
  function upload()
  {
   $config['upload_path'] = './web-project-jb/assets/uploads/';
   $config['allowed_types'] = 'gif|jpg|jpeg|png';
   $config['max_size'] = '10000';
   $config['max_width'] = '1024';
   $config['max_height'] = '768';
  
   $this->load->library('upload', $config);
   $img = $this->session->userdata('img');
   $username = $this->session->userdata('username');
   $this->profileimages->putProfileImage($username, $this->input->post("profileimage"));
   //fail show upload form
   if (! $this->upload->do_upload())
   {
  
    $error = array('error'=>$this->upload->display_errors());
    
    $username = $this->session->userdata('username');
    
    
    $viewData['username'] = $username;
    $viewData['profileText'] = $this->profiles->getProfileText($username);
    
    $this->load->view('shared/header');
    $this->load->view('homeprofile/homeprofiletitle', $viewData);
    $this->load->view('shared/nav');
    $this->load->view('homeprofile/upload_fail', $error);
    $this->load->view('homeprofile/homeprofileview', $viewData, array('error' => ' ' ));
    $this->load->view('shared/footer');
    
    //redirect('homeprofile/index');
  
   }
  
   else
   {
    //successful upload so save to database
    
    
    $file_data = $this->upload->data();
    
    
    $data['img'] = base_url().'./web-project-jb/assets/uploads/'.$file_data['file_name'];
    // you may want to delete the image from the server after saving it to db
    // check to make sure $data['full_path'] is a valid path
    // get upload_sucess.php from link above
    //$image = chunk_split( base64_encode( file_get_contents( $data['file_name'] ) ) );
    

    
    $this->username = $this->session->userdata('username');
  
    $data['profileimages'] = $this->profileimages->getProfileImage($username);
    
    
    $viewData['username'] = $username;
    $viewData['profileText'] = $this->profiles->getProfileText($username);
    
    $username = $this->session->userdata('username');
    
    redirect('homeprofile/index');
   }
  
  }
  

  
  function index()
  {
  
   $username = $this->session->userdata('username');
  
   $data['profileimages'] = $this->profileimages->getProfileImage($username);
    
   $viewData['username'] = $username;
   $viewData['profileText'] = $this->profiles->getProfileText($username);
    
   $this->load->view('shared/header');
   $this->load->view('homeprofile/homeprofiletitle', $viewData);
   $this->load->view('shared/nav');
   //$this->load->view('homeprofile/upload_form', $data);
   $this->load->view('homeprofile/homeprofileview', $data, $viewData, array('error' => ' ' ) );
   $this->load->view('shared/footer');
  }

}

Here is my view :
Code:
<div id="maincontent">
   <div id="primary">
   &lt;?//=$error;?&gt;
    &lt;?//=$img;?&gt;
    <h3>&lt;?="Profile Image"?&gt;</h3>
     <img src="&lt;?php echo'$img'?&gt;" width='300' height='300'/>
      &lt;?=form_open_multipart('homeprofile/upload');?&gt;
        &lt;input type="file" name="img" value=""/&gt;
        &lt;?=form_submit('submit', 'upload')?&gt;
        &lt;?=form_close();?&gt;
        &lt;?php if (isset($error)) echo $error;?&gt;
      </div>
    </div>

And one other thing. even when the folder upload was working, when I uploaded an image just the outline of the image would appear as if corrupt. why could this be?





Messages In This Thread
I am uploading a profile image into a database but they do not upload into my uploads folder - by El Forum - 11-15-2012, 03:51 PM



Theme © iAndrew 2016 - Forum software by © MyBB