Welcome Guest, Not a member yet? Register   Sign In
Image Upload
#1

Hello,

I try to upload an image:

The upload path does not appear to be valid.

Why does that error appears?


http://jamshidhashimi.com/2011/06/14/ima...igniter-2/


controllers/Site.php


PHP Code:
<?php

//Author: Jamshid HASHIMI
 
 
 class Upload extends CI_Controller
 
  
{
 
 
   function __construct()
 
 
   {
 
 
       parent::__construct();
 
 
       $this->load->helper('form');
 
 
       $this->load->helper('url');
 
 
    
 
    function index
()
 
 
   {
 
 
       $this->load->view('upload_view');
 
 
   }
 
 
   //Upload Image function
 
 
   function uploadImage()
 
 
   {
 
 
      $config['upload_path'    "uploads/";
 
 
      $config['allowed_types'] =   "gif|jpg|jpeg|png"
 
 
      $config['max_size'       "5000";
 
 
      $config['max_width'      "1907";
 
 
      $config['max_height'     "1280";
 
 
      $this->load->library('upload',$config);
 
 
      if(!$this->upload->do_upload())
 
 
      {
 
 
          echo $this->upload->display_errors();
 
 
      }
 
 
      else
 
 
      {
 
 
          $finfo=$this->upload->data();
 
 
          $this->_createThumbnail($finfo['file_name']);
 
 
          $data['uploadInfo'] = $finfo;
 
 
          $data['thumbnail_name'] = $finfo['raw_name']. '_thumb' .$finfo['file_ext']; 
 
 
          $this->load->view('upload_success',$data);
 
 
          // You can view content of the $finfo with the code block below
 
 
          /*echo '<pre>';
 
           print_r($finfo);
 
           echo '</pre>';*/
 
 
      }
 
 
   }
 
 
   //Create Thumbnail function
 
 
   function _createThumbnail($filename)
 
 
   {
 
 
       $config['image_library'   "gd2"     
 
        $config
['source_image'    "uploads/" .$filename     
 
        $config
['create_thumb'    TRUE     
 
        $config
['maintain_ratio'  TRUE     
 
        $config
['width'] = "80"     
 
        $config
['height'] = "80";
 
 
       $this->load->library('image_lib',$config);
 
 
       if(!$this->image_lib->resize())
 
 
       {
 
 
           echo $this->image_lib->display_errors();
 
 
            
 
    
}
 
 
 }
 
?>


views/upload_view.php


PHP Code:
<html>
 
<
head>
 
<
titleImage Upload </title>
 
</
head>
 
<
body>
 
<
div id="container">
 
<?
php echo  form_open_multipart('upload/uploadImage')?>
 
<input type="file" name="userfile" />
 
<p><input type="submit" name="submit" value="submit" /></p>
 
<?php echo form_close();?>
 
</div>
 
</body>
 
</html> 



views/upload_success.php


PHP Code:
<html>
 
<
head>
 
<
titleImage Upload </title>
 
</
head>
 
<
body>
 
<
div id="container">
 
<
dl>
 
 
   <dt>
 
 
       File Name:
 
 
   </dt>
 
 
   <dd>
 
 
       <?php echo $uploadInfo['file_name'];?>
 
    </dd>
 
    <dt>
 
        File Size:
 
    </dt>
 
    <dd>
 
        <?php echo $uploadInfo['file_size'];?>
 
    </dd>
 
    <dt>
 
        File Extension:
 
    </dt>
 
    <dd>
 
        <?php echo $uploadInfo['file_ext'];?>
 
    </dd>
 
    <br />
 
    <p>The Image:</p>
 
    <img alt="Your uploaded image" src="<?=base_url(). 'uploads/' $uploadInfo['file_name'];?>"> 
 
    <p>The Image:</p> 
 
    <img alt="Your Thumbnail image" src="<?=base_url(). 'uploads/' $thumbnail_name;?>">  
 
</dl>
 
</div>
 
</body>
 
</html> 
" If I looks more intelligence please increase my reputation."
Reply


Messages In This Thread
Image Upload - by davy_yg - 05-10-2016, 11:30 PM
RE: Image Upload - by PaulD - 05-11-2016, 01:12 AM



Theme © iAndrew 2016 - Forum software by © MyBB