codeigniter - undefined variable $error in file uploading class codeingiter -


I am trying to use the Codeigniter upload class to upload pdfs to a folder that is working fine . However, the error variable is visible as undefined and for this reason I am not seeing the error if I am uploading the wrong file. Please suggest.

This is my view,

  & lt ;? Echo echo php $ ;? & Gt; & Lt ;? Php echo form_open_multipart ('admin / admin_elements / do_upload_pdf') ;? & Gt; & Lt; Input type = "file" name = "pdf" class = "btn" /> & Lt; Br / & gt; & Lt; Br / & gt; & Lt; Input type = "submit" class = "btn btn-info" value = "upload" / & gt; & Lt ;? Php echo form_close (); ? & Gt;  

and my controller function,

  function add_pdf () {$ data ['main_content'] = 'admin / elements / add_pdf'; $ This- & gt; Load-> View ('/ template', $ data included); } Function do_upload_pdf () {$ config ['upload_path'] = './uploads/'; $ Config ['allowed_types'] = 'pdf'; $ Config ['max_size'] = '10000'; $ This- & gt; Load-> Library ('upload', $ config); If (! $ This- & gt; upload-> do_upload ('pdf')) {$ error = array ('error' => $ this-> upload-> display_errors ()); $ Data ['main_content'] = 'admin / element / ad_pdf'; $ This- & gt; Load-> View ('/ template', $ data included); } And {$ chapter_id = $ this- & gt; Session-> User Data ('Chapter_ID'); Redirect ("/ admin / elements /" .$ chapter_id); }}  

Thanks.

Add this line to add_pdf () { < Pre> $ data ["error"] = "";

and do_upload_pdf ()

  if (! $ This-> upload- & gt; do_upload ('pdf ')) {$ Data [' error '] = $ this- & gt; Upload-> Display_rars (); $ Data ['main_content'] = 'admin / element / ad_pdf'; $ This- & gt; Load-> View ('/ template', $ data included); }  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -