view image

Discussion in 'PHP' started by shiva478, Aug 23, 2012.

  1. #1
    I was doing a tutorial on file uploading class in codeigniters userguide.
    I was able to insert the image path into my database. The only problem I have is that when I try to view the image I get a broken picture like one usually gets when you can't view the picture.

    This is my upload controller
    
    [COLOR=#0000BB][FONT=monospace]<?php
    
    [/FONT][/COLOR][COLOR=#007700][FONT=monospace]class [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Upload [/FONT][/COLOR][COLOR=#007700][FONT=monospace]extends [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]CI_Controller {
    
     [/FONT][/COLOR][COLOR=#007700][FONT=monospace]function [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]__construct[/FONT][/COLOR][COLOR=#007700][FONT=monospace]()
     [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]{
      parent[/FONT][/COLOR][COLOR=#007700][FONT=monospace]::[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]__construct[/FONT][/COLOR][COLOR=#007700][FONT=monospace]();
      [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$this[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]load[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]model[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'upload_model'[/FONT][/COLOR][COLOR=#007700][FONT=monospace]);
      [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$this[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]load[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]helper[/FONT][/COLOR][COLOR=#007700][FONT=monospace](array([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'form'[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'url'[/FONT][/COLOR][COLOR=#007700][FONT=monospace]));
     [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]}
    
     [/FONT][/COLOR][COLOR=#007700][FONT=monospace]function [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]index[/FONT][/COLOR][COLOR=#007700][FONT=monospace]()
     [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]{
      $this[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]load[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]view[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'upload_form'[/FONT][/COLOR][COLOR=#007700][FONT=monospace], array([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'error' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]=> [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]' ' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]));
     [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]}
    
     [/FONT][/COLOR][COLOR=#007700][FONT=monospace]function [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]do_upload[/FONT][/COLOR][COLOR=#007700][FONT=monospace]()
     [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]{
      $config[[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'upload_path'[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]] [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'./uploads/'[/FONT][/COLOR][COLOR=#007700][FONT=monospace];
      [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$config[[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'allowed_types'[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]] [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'gif|jpg|png'[/FONT][/COLOR][COLOR=#007700][FONT=monospace];
      [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$config[[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'max_size'[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]] [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'100'[/FONT][/COLOR][COLOR=#007700][FONT=monospace];
      [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$config[[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'max_width'[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]]  [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'1024'[/FONT][/COLOR][COLOR=#007700][FONT=monospace];
      [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$config[[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'max_height'[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]]  [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'768'[/FONT][/COLOR][COLOR=#007700][FONT=monospace];
    
      [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$this[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]load[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]library[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'upload'[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$config[/FONT][/COLOR][COLOR=#007700][FONT=monospace]);
    
      if ( ! [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$this[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]upload[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]do_upload[/FONT][/COLOR][COLOR=#007700][FONT=monospace]())
      [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]{
       $error [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= array([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'error' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]=> [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$this[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]upload[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]display_errors[/FONT][/COLOR][COLOR=#007700][FONT=monospace]());
    
       [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$this[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]load[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]view[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'upload_form'[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$error[/FONT][/COLOR][COLOR=#007700][FONT=monospace]);
      [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]}
      [/FONT][/COLOR][COLOR=#007700][FONT=monospace]else
      [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]{
       $data [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= array([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'upload_data' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]=> [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$this[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]upload[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]data[/FONT][/COLOR][COLOR=#007700][FONT=monospace]());
       [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$upload_info [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$this[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]upload[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]data[/FONT][/COLOR][COLOR=#007700][FONT=monospace]();
       
       [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$insert_data [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= array(
                  [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'id' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]=> [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$this[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]input[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]post[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'id'[/FONT][/COLOR][COLOR=#007700][FONT=monospace]),
                  [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'image_path' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]=> [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$upload_info[[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'file_path'[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]][/FONT][/COLOR][COLOR=#007700][FONT=monospace],
                  [/FONT][/COLOR]
    Code (markup):
    'filename' => $upload_info['file_name'],[COLOR=#27343C][FONT=Arial][COLOR=#007700][FONT=monospace]
                  [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'content' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]=> [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$this[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]input[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]post[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'content'[/FONT][/COLOR][COLOR=#007700][FONT=monospace])
                 );
       [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$this[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]db[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]insert[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'image'[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$insert_data[/FONT][/COLOR][COLOR=#007700][FONT=monospace]);
    
    
       [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$this[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]load[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]view[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'upload_success'[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$data[/FONT][/COLOR][COLOR=#007700][FONT=monospace]);
      
      [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]}
     }
     
     [/FONT][/COLOR][COLOR=#007700][FONT=monospace]function [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]view[/FONT][/COLOR][COLOR=#007700][FONT=monospace]()[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]{
      
      $data[[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'title'[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]] [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"Voluptuous Decadents"[/FONT][/COLOR][COLOR=#007700][FONT=monospace];
      [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$data[[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'heading'[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]] [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"Bras"[/FONT][/COLOR][COLOR=#007700][FONT=monospace];
      [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$data[[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'query'[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]] [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$this[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]db[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]get[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'image'[/FONT][/COLOR][COLOR=#007700][FONT=monospace]);
      
      [/FONT][/COLOR][COLOR=#FF8000][FONT=monospace]//$this->load->view('layout');   
      [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$this[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]load[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]view[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'view'[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$data[/FONT][/COLOR][COLOR=#007700][FONT=monospace]);
     [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]}
    }
    ?> [/FONT][/COLOR]
    [/FONT][/COLOR]
    Code (markup):


    This is my upload_model
    
    [COLOR=#0000BB][FONT=monospace]<?php
    [/FONT][/COLOR][COLOR=#007700][FONT=monospace]class [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Upload_model [/FONT][/COLOR][COLOR=#007700][FONT=monospace]extends [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]CI_Model {
    
     [/FONT][/COLOR][COLOR=#007700][FONT=monospace]public function [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]__construct[/FONT][/COLOR][COLOR=#007700][FONT=monospace]()
     [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]{
      $this[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]load[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]database[/FONT][/COLOR][COLOR=#007700][FONT=monospace]();
     [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]}
     
     [/FONT][/COLOR][COLOR=#007700][FONT=monospace]public function [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]get_upload[/FONT][/COLOR][COLOR=#007700][FONT=monospace]()
    [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]{
     
     
      $query [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$this[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]db[/FONT][/COLOR][COLOR=#007700][FONT=monospace]->[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]get[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'image'[/FONT][/COLOR][COLOR=#007700][FONT=monospace]);
     
    [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]}
    }
    ?> [/FONT][/COLOR]
    
    Code (markup):
    This is my upload_form
    
    [COLOR=#007700][FONT=monospace]<[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]html[/FONT][/COLOR][COLOR=#007700][FONT=monospace]>
    <[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]head[/FONT][/COLOR][COLOR=#007700][FONT=monospace]>
    <[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]title[/FONT][/COLOR][COLOR=#007700][FONT=monospace]>[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Upload Form[/FONT][/COLOR][COLOR=#007700][FONT=monospace]</[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]title[/FONT][/COLOR][COLOR=#007700][FONT=monospace]>
    </[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]head[/FONT][/COLOR][COLOR=#007700][FONT=monospace]>
    <[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]body[/FONT][/COLOR][COLOR=#007700][FONT=monospace]>
    
    [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]<?php [/FONT][/COLOR][COLOR=#007700][FONT=monospace]echo [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$error[/FONT][/COLOR][COLOR=#007700][FONT=monospace];[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]?>
    
    <?php [/FONT][/COLOR][COLOR=#007700][FONT=monospace]echo [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]form_open_multipart[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'upload/do_upload'[/FONT][/COLOR][COLOR=#007700][FONT=monospace]);[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]?>
    
    [/FONT][/COLOR][COLOR=#007700][FONT=monospace]<[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]input type[/FONT][/COLOR][COLOR=#007700][FONT=monospace]=[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"file" [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]name[/FONT][/COLOR][COLOR=#007700][FONT=monospace]=[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"userfile" [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]size[/FONT][/COLOR][COLOR=#007700][FONT=monospace]=[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"20" [/FONT][/COLOR][COLOR=#007700][FONT=monospace]/>
    [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]<?php [/FONT][/COLOR][COLOR=#007700][FONT=monospace]echo [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]form_input[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'content'[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]set_value[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'content'[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'content'[/FONT][/COLOR][COLOR=#007700][FONT=monospace]));[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]?>
    [/FONT][/COLOR][COLOR=#007700][FONT=monospace]<[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]br [/FONT][/COLOR][COLOR=#007700][FONT=monospace]/><[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]br [/FONT][/COLOR][COLOR=#007700][FONT=monospace]/>
    
    <[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]input type[/FONT][/COLOR][COLOR=#007700][FONT=monospace]=[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"submit" [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]value[/FONT][/COLOR][COLOR=#007700][FONT=monospace]=[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"upload" [/FONT][/COLOR][COLOR=#007700][FONT=monospace]/>
    
    </[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]form[/FONT][/COLOR][COLOR=#007700][FONT=monospace]>
    [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]<?php [/FONT][/COLOR][COLOR=#007700][FONT=monospace]echo [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]anchor[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'upload/view'[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'view'[/FONT][/COLOR][COLOR=#007700][FONT=monospace]); [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]?>
    [/FONT][/COLOR][COLOR=#007700][FONT=monospace]</[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]body[/FONT][/COLOR][COLOR=#007700][FONT=monospace]>
    </[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]html[/FONT][/COLOR][COLOR=#007700][FONT=monospace]> [/FONT][/COLOR]
    
    Code (markup):
    This is my upload_success view
    
    [COLOR=#007700][FONT=monospace]<[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]html[/FONT][/COLOR][COLOR=#007700][FONT=monospace]>
    <[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]head[/FONT][/COLOR][COLOR=#007700][FONT=monospace]>
    <[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]title[/FONT][/COLOR][COLOR=#007700][FONT=monospace]>[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Upload Form[/FONT][/COLOR][COLOR=#007700][FONT=monospace]</[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]title[/FONT][/COLOR][COLOR=#007700][FONT=monospace]>
    </[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]head[/FONT][/COLOR][COLOR=#007700][FONT=monospace]>
    <[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]body[/FONT][/COLOR][COLOR=#007700][FONT=monospace]>
    
    <[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]h3[/FONT][/COLOR][COLOR=#007700][FONT=monospace]>[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Your file was successfully uploaded[/FONT][/COLOR][COLOR=#007700][FONT=monospace]!</[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]h3[/FONT][/COLOR][COLOR=#007700][FONT=monospace]>
    
    <[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]ul[/FONT][/COLOR][COLOR=#007700][FONT=monospace]>
    [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]<?php [/FONT][/COLOR][COLOR=#007700][FONT=monospace]foreach ([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$upload_data [/FONT][/COLOR][COLOR=#007700][FONT=monospace]as [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$item [/FONT][/COLOR][COLOR=#007700][FONT=monospace]=> [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$value[/FONT][/COLOR][COLOR=#007700][FONT=monospace]):[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]?>
    [/FONT][/COLOR][COLOR=#007700][FONT=monospace]<[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]li[/FONT][/COLOR][COLOR=#007700][FONT=monospace]>[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]<?php [/FONT][/COLOR][COLOR=#007700][FONT=monospace]echo [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$item[/FONT][/COLOR][COLOR=#007700][FONT=monospace];[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]?>[/FONT][/COLOR][COLOR=#007700][FONT=monospace]: [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]<?php [/FONT][/COLOR][COLOR=#007700][FONT=monospace]echo [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$value[/FONT][/COLOR][COLOR=#007700][FONT=monospace];[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]?>[/FONT][/COLOR][COLOR=#007700][FONT=monospace]</[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]li[/FONT][/COLOR][COLOR=#007700][FONT=monospace]>
    
    [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]<?php [/FONT][/COLOR][COLOR=#007700][FONT=monospace]endforeach; [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]?>
    [/FONT][/COLOR][COLOR=#007700][FONT=monospace]</[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]ul[/FONT][/COLOR][COLOR=#007700][FONT=monospace]>
    
    <[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]p[/FONT][/COLOR][COLOR=#007700][FONT=monospace]>[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]<?php [/FONT][/COLOR][COLOR=#007700][FONT=monospace]echo [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]anchor[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'upload'[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'Upload Another File!'[/FONT][/COLOR][COLOR=#007700][FONT=monospace]); [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]?>[/FONT][/COLOR][COLOR=#007700][FONT=monospace]</[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]p[/FONT][/COLOR][COLOR=#007700][FONT=monospace]>
    
    
    
    
    </[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]body[/FONT][/COLOR][COLOR=#007700][FONT=monospace]>
    </[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]html[/FONT][/COLOR][COLOR=#007700][FONT=monospace]> [/FONT][/COLOR]
    
    Code (markup):
    This is my view
    
    
    Code (markup):
    <html>
    <head>
    
    
    <title><?php echo $title; ?></title>
    </head>
    
    
        <body>
    
    
    
    
    <h1><?php echo $heading ?></h1>
    
    
    <?php foreach($query->result() as $row): ?>
    
    
    <p><?php echo $row->content ?></p>
    <?php //echo $row->image_path; ?>
    <?php echo $row->filename; ?>
    <img src="<?php echo $row->filename; ?>" />
    [COLOR=#27343C][FONT=Arial][COLOR=#007700][FONT=monospace]
    
    
    [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]<?php [/FONT][/COLOR][COLOR=#007700][FONT=monospace]endforeach; [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]?>
    
    [/FONT][/COLOR][COLOR=#007700][FONT=monospace]<[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]body[/FONT][/COLOR][COLOR=#007700][FONT=monospace]>
    </[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]html[/FONT][/COLOR][COLOR=#007700][FONT=monospace]> [/FONT][/COLOR]
    [/FONT][/COLOR]
    Code (markup):

     
    shiva478, Aug 23, 2012 IP
  2. fastestsms

    fastestsms Greenhorn

    Messages:
    72
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    6
    #2
    I think you should use some en/decryption method to encrypt your image content before inserting it to database and then decrypt it after selecting from DB. You can try with base64_decode, base64_encode function. But it's not a good idea to store something like images in database, will be big problem when backup/restore... 8->
     
    fastestsms, Aug 26, 2012 IP
  3. mastjaat

    mastjaat Member

    Messages:
    64
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    <?php
    if(isset($_POST['upload']))
    {
    $path="image/";
    $path=$path.$_FILES['f_nm']['name'];
    if($_FILES['f_nm']['size']>0)
    {
    move_uploaded_file($_FILES['f_nm']['tmp_name'],$path);
    echo"The Image ". basename($_FILES['f_nm']['name'])." uploaded";
    }
    }
    /////////READING IMAGE'S NAME FROM IMAGE DIRECTORY/////////

    $dp=opendir("image");
    while($fn=readdir($dp))
    {
    if($fn!='.'&&$fn!='..'&&$fn!='Thumbs.db')
    $fnm[]=$fn;
    }


    ?>
    <form action="" method="post" enctype="multipart/form-data">
    <table width="100%" border="1" align="center">
    <tr>
    <td width="318" height="155"><table width="33%" border="0" align="center" bgcolor="#99CCCC">
    <tr>
    <td height="258"><center>
    <?php
    $tot=count($fnm);
    $no_row=ceil($tot/5);
    $i=1;
    echo"<table>";
    for($r=1;$r<=$no_row;$r++)
    {
    echo "<tr>";
    for($c=1;$c<=5&&$i<=$tot;$i++,$c++)
    {
    list($k,$v)=each($fnm);
    echo "<td><a href='photogallery.php?id=$v'><img src='image/$v' height='50' width='50'></a></td>";
    }
    echo "</tr>";
    }
    echo"</table>";
    ?>
    </center></td>
    </tr>
    <tr>
    <td height="68"><table width="312" border="0">
    <tr>
    <td width="81">Upload File </td>
    <td width="221"><input type="file" name="f_nm" /></td>
    </tr>
    <tr>
    <td><input name="upload" type="submit" id="upload" value="Upload" /></td>
    <td>&nbsp;</td>
    </tr>
    </table></td>
    </tr>
    </table></td>
    <td width="306" bgcolor="#669999">&nbsp;</td>
    </tr>
    </table>
    </form>
     
    mastjaat, Aug 29, 2012 IP