Example of using the CodeIgniter class library to upload images

Source: Internet
Author: User
Example of using the CodeIgniter class library to upload images

2. file Upload class:

  1. Public function img_upload ()

  2. {
  3. $ This-> load-> helper ('URL ');

  4. $ Config ['upload _ path'] = './images/'. date ('ym', time ()).'/';

  5. $ Config ['allowed _ types'] = 'gif | jpg | png ';
  6. $ Config ['File _ name'] = date ('Y _ m_d ', time ().' _ '. sprintf (' % 02d ', rand (0, 99 ));
  7. $ Config ['max _ size'] = '000000 ';
  8. $ Config ['max _ width'] = '000000 ';
  9. $ Config ['max _ height'] = '20140901 ';

  10. $ This-> load-> library ('upload', $ config );

  11. If (! $ This-> upload-> do_upload ())

  12. {
  13. $ Error = array ('error' => $ this-> upload-> display_errors ());
  14. }
  15. Else
  16. {
  17. $ Data = array ('upload _ data' => $ this-> upload-> data ());
  18. }
  19. }

Required functions: $ this-> upload-> do_upload (): configure parameters according to preference to perform the operation. Note: By default, the uploaded file is from the file field named userfile in the submitted form, and the form must be of the "multipart" type. $ This-> upload-> display_errors (): If do_upload () fails to return, an error message is displayed. This function does not automatically output but returns data, so you can arrange it as required. $ This-> upload-> data (): Helper function, which returns an array of all relevant information of the uploaded file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.