isimpledesign Posted November 25, 2010 Share Posted November 25, 2010 Hi guys really need some help. i have got this function. I am learning codeignitor. function uploadify() { $file = $this->input->post('filearray'); $data['json'] = json_decode($file); print_r($data); $name = $json->{'file_name'}; $this->files->add($name); $this->load->view('uploadify',$data); } this is the result i get from the print_r(). Array ( [json] => stdClass Object ( [file_name] => footer-icpn229.jpg [real_name] => footer-icpn2.jpg [file_ext] => .jpg [file_size] => 1.75 [file_path] => /home/codeig/public_html/files/footer-icpn229.jpg [file_temp] => /home/codeig/tmp/phpSupCpi ) ) What i am trying to do is pull the value filename out off the array and pass it into another vairable in the fucntion which is what i am trying to do with these two lines of code. $name = $json->{'file_name'}; $this->files->add($name); I keep getting this error what am i doing wrong? Undefined variable: json Quote Link to comment https://forums.phpfreaks.com/topic/219809-grabbing-key-out-off-array-for-use-within-function/ Share on other sites More sharing options...
trq Posted November 26, 2010 Share Posted November 26, 2010 As the error states, $json isn't defined anywhere with you code. Use... $name = $data['json']->file_name; Quote Link to comment https://forums.phpfreaks.com/topic/219809-grabbing-key-out-off-array-for-use-within-function/#findComment-1139718 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.