これらのサイトを見てください
次に、以下の擬似コードに従います(profileimageがデータベースにBLOBフィールドとして格納されていると仮定します)
モデルファイル:
function putProfileImage($user, $image)
{
// you may need to store the image type / mine type
$record = array('user' => $user, 'profileimage' => $image);
if ($this->exists($user))
{
$this->db->update('profiles', $record)->where('user', $user);
}
else
{
$this->db->insert('profiles', $record);
}
}
function getProfileImage($user)
{
$this->db->select('*')->from('profiles')->where('user', $user);
$query = $this->db->get();
if ($query->num_rows() > 0){
$row = $query->row();
return $row->profileimage; //Trying to get property of non-object error
}
return Null;
}
コントローラー-profile.php
function Upload()
{
// see - Creating the Upload Form
// @ - http://codeigniter.com/user_guide/libraries/file_uploading.html
}
function doUpload ()
{
//see do_upload() and save with module above
// @ - http://codeigniter.com/user_guide/libraries/file_uploading.html
}
function displayImage()
{
//Retrieve image id from the URI
$imageid = $this->uri->segment(3);
//Initialize the images model
$this->load->model("image_model");
//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"/>';
}