Welcome Guest, Not a member yet? Register   Sign In
upload image
#1

Hello,

I trying to practice uploading image:

http://www.codersmount.com/2012/11/uploa...deigniter/

I don't think it works:

views/main.php

PHP Code:
<?php
  $image 
= array(
 
   'name'  =>  'userfile',
 
   'id'    =>  'userfile',
 
   );
 
    
  $submit 
= array(
 
   'name'  => 'submit',
 
   'id'    => 'submit',
 
   'value' => 'Upload'
 
   );
?>
<?php 
echo form_open_multipart('upload/upload_image''id=upload_file'); ?>
<?php 
echo form_upload($image); ?>
<?php 
echo form_submit($submit); ?>
<?php 
echo form_close(); ?>


controllers/upload.php

PHP Code:
class Upload extends CI_Controller{
    
    public function 
index()
    {
        
$this->load->view('main');
    }    
    
 
   public function upload_image(){
 
       $this->upload_model->do_upload(); //execute the upload function
        
        
 
   }



models/upload_model.php

PHP Code:
<?php
class User_model extends CI_Model{
 
 var $original_path;
 
 var $resized_path;
 
 var $thumbs_path;
 
 
 //initialize the path where you want to save your images
 
 function __construct(){
 
   parent::__construct();
 
   //return the full path of the directory
 
   //make sure these directories have read and write permessions
 
   $this->original_path realpath(APPPATH.'../uploads/original');
 
   $this->resized_path realpath(APPPATH.'../uploads/resized');
 
   $this->thumbs_path realpath(APPPATH.'../uploads/thumbs');
 
 }
 
 
 function do_upload(){
 
   $this->load->library('image_lib');
 
   $config = array(
 
   'allowed_types'     => 'jpg|jpeg|gif|png'//only accept these file types
 
   'max_size'          => 2048//2MB max
 
   'upload_path'       => $this->original_path //upload directory
 
 );
 
 
   $this->load->library('upload'$config);
 
   $image_data $this->upload->data(); //upload the image
 
 
   //your desired config for the resize() function
 
   $config = array(
 
   'source_image'      => $image_data['full_path'], //path to the uploaded image
 
   'new_image'         => $this->resized_path//path to
 
   'maintain_ratio'    => true,
 
   'width'             => 128,
 
   'height'            => 128
    
);
 
 
   //this is the magic line that enables you generate multiple thumbnails
 
   //you have to call the initialize() function each time you call the resize()
 
   //otherwise it will not work and only generate one thumbnail
 
   $this->image_lib->initialize($config);
 
   $this->image_lib->resize();
 
 
   $config = array(
 
   'source_image'      => $image_data['full_path'],
 
   'new_image'         => $this->thumbs_path,
 
   'maintain_ratio'    => true,
 
   'width'             => 36,
 
   'height'            => 36
    
);
 
   //here is the second thumbnail, notice the call for the initialize() function again
 
   $this->image_lib->initialize($config);
 
   $this->image_lib->resize();
 
 }



I also get this error message:


http://localhost/upload/


Fatal error: Call to undefined function form_open_multipart() in C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\upload\application\views\main.php on line 14
A PHP Error was encountered
Severity: Error
Message: Call to undefined function form_open_multipart()
Filename: views/main.php
Line Number: 14
Backtrace:


Can anyone help me fix this error?

Thanks in advance.
" If I looks more intelligence please increase my reputation."
Reply


Messages In This Thread
upload image - by davy_yg - 05-09-2016, 11:50 PM
RE: upload image - by JayAdra - 05-10-2016, 12:23 AM
RE: upload image - by davy_yg - 05-10-2016, 08:32 PM
RE: upload image - by JayAdra - 05-10-2016, 09:24 PM



Theme © iAndrew 2016 - Forum software by © MyBB