Welcome Guest, Not a member yet? Register   Sign In
Undefined variable: media_path for uploading image
#1

[eluser][email protected][/eluser]
The line #86 is : $files = scandir($this->$media_path); //standard PHP function
The result in below code returns:
Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined variable: media_path

Filename: models/post_model.php

Line Number: 86

Fatal error: Cannot access empty property in C:\xampp\htdocs\user_files\chenwei_huang\analyst\system\core\Model.php on line 51


Code:
<?php

class Post_model extends CI_Model {
var $media_path;//Upload Media Files
var $media_path_url;

function Post_model() {
  parent:: CI_Model;
  $this->media_path = realpath(APPPATH.'../images');//Upload Media Files
  $this->media_path_url = base_url().'images/';
  
  
}

public function __construct(){
  $this->media_path = realpath(APPPATH.'../images');//Upload Media Files
  $this->media_path_url = base_url().'images/';
  $this->load->database();
  
  //$this->media_path = realpath(APPPATH.'../images');//Upload Media Files
  //$this->media_path_url = base_url().'images/';
  //$this->load->helper('url'); //This function - provided by the URL helper - strips down the string you pass it, replacing  
         //all spaces by dashes (-) and makes sure everything is in lowercase characters. This leaves  
         //you with a nice slug, perfect for creating URIs.
}

public function get_post($pos_slug = FALSE){
  if ($pos_slug === FALSE){
   $query = $this->db->get('post');
   return $query->result_array();
  }
  $query = $this->db->get_where('post', array('pos_slug' => $pos_slug));
  return $query->row_array();
}

public function set_post(){
  $pos_slug = url_title($this->input->post('pos_title'), 'dash', TRUE);
  $data = array(
   'pos_title' => $this->input->post('pos_title'), //the post() method from the input library. This method makes sure the data is
               //sanitized, protecting you from nasty attacks from others. The input library
               //is loaded by default. At last, you insert our $data array into our database.
   'pos_slug' => $pos_slug,
   'pos_desc' => $this->input->post('pos_desc')
  );  
  return $this->db->insert('post', $data);
}

public function deletepost() {
  $this->db->where('pos_id',$this->uri->segment(3,0));
  //$this->db->where('pos_id',$this->uri->segment(3,0));
  echo 'DeltePost Ran';
  $this->db->delete('post');
  /*$this->db->where(“example_id”, $this->example_id);
  $this->db->delete(“examples”);*/
}

/*Upload Media Files BEG*/


function do_media_upload() {
  $config = array(
   'allowed_types'=> 'jpg|jepg|gif|png',
   'upload_path'=> $this->$media_path,
   'max_size'=>2000 //its 2MB = 2000
  );
  
  //$this->load->library('upload', $config);
  $this->load->library('upload', $config);
  $this->upload->do_media_upload();
  
  $image_data=$this->upload->data();
  
  $config = array(
   'source_image'=> $image_data['full_path'],
   'new_image'=> $this->$media_path.'/thumbs',
   'maintain_ratio'=>true, //
   'width'=> 150,
   'height' => 100
  );
  
  $this->load->library('image_lib', $config);
  $this->image_lib->resize();
}//do_media_upload() END

function get_images(){
  $files = scandir($this->$media_path); //standard PHP function
  $files = array_diff($files, array('.', '..','thumbs'));
  $images = array();
  foreach ($files as $file) {
   $images[] = array (
    'url' => $this->meida_file_url.$file,
    'thumb_url' => $this->meida_file_url.'/thumbs'.$file
   );
  };
  
}



/*Upload Media Files END*/
}
#2

[eluser]Ckirk[/eluser]
You'll kick yourself when i tell you :p
Code:
$files = scandir($this->media_path); //removed the $ symbol from "$this->$media_path"
#3

[eluser]CroNiX[/eluser]
He also did that in the $config array.

And also misspelled "media" used here (get_images method), and shouldn't it be "media_path_url" anyway instead of media_file_url?:
Code:
$images[] = array (
    'url' => $this->meida_file_url.$file,
    'thumb_url' => $this->meida_file_url.'/thumbs'.$file
   );




Theme © iAndrew 2016 - Forum software by © MyBB