Front-end code {code ...} controller: define an array and set some upload-related parameters {code ...} call the CI Upload generic class and execute the upload {code ...} receive error message or success message {code ...} {code ...} front-end code
Controller:
Define an array and set upload-related parameters
$ Config ['upload _ path'] = '. /uploads/'; // Set the upload type $ config ['allowed _ types'] = 'gif | jpg | png '; $ config ['max _ size'] = '000000'; // you can set the maximum height and width for an image. $ config ['max _ height'] = 100; $ config ['max _ width'] = 1024;
Call the CI Upload generic class and execute the Upload
// Upload is the name of the called class, all in lower case $ this-> load-> library ('upload', $ config); // if the name of the upload box is userfile, you do not need to pass the parameter. if not, transfer the name value to $ this-> upload-> do_upload ('upload box name ');
Receive error message or successful message
// Error message $ error = array ('error' => $ this-> upload-> display_error ()); // success information $ data = array ('upload _ data' = >$ this-> upload-> data ());
Load-> view ('up');} // display the upload information. public function up () {$ config ['upload _ path'] = '. /uploads/'; $ config ['allowed _ types'] = 'gif | jpg | png '; $ config ['max _ size'] = "2000 "; $ this-> load-> library ('upload', $ config ); // Print the success or error message if ($ this-> upload-> do_upload ('upfile ')) {$ data = array ("upload_data" = >$ this-> upload-> data (); var_dump ($ data );} else {$ error = array ("error" => $ this-> upload-> display_errors (); var_dump ($ error );}}}
Front-end code
Controller:
Define an array and set upload-related parameters
$ Config ['upload _ path'] = '. /uploads/'; // Set the upload type $ config ['allowed _ types'] = 'gif | jpg | png '; $ config ['max _ size'] = '000000'; // you can set the maximum height and width for an image. $ config ['max _ height'] = 100; $ config ['max _ width'] = 1024;
Call the CI Upload generic class and execute the Upload
// Upload is the name of the called class, all in lower case $ this-> load-> library ('upload', $ config); // if the name of the upload box is userfile, you do not need to pass the parameter. if not, transfer the name value to $ this-> upload-> do_upload ('upload box name ');
Receive error message or successful message
// Error message $ error = array ('error' => $ this-> upload-> display_error ()); // success information $ data = array ('upload _ data' = >$ this-> upload-> data ());
Load-> view ('up');} // display the upload information. public function up () {$ config ['upload _ path'] = '. /uploads/'; $ config ['allowed _ types'] = 'gif | jpg | png '; $ config ['max _ size'] = "2000 "; $ this-> load-> library ('upload', $ config ); // Print the success or error message if ($ this-> upload-> do_upload ('upfile ')) {$ data = array ("upload_data" = >$ this-> upload-> data (); var_dump ($ data );} else {$ error = array ("error" => $ this-> upload-> display_errors (); var_dump ($ error );}}}
For more articles on image uploading in the ci framework, refer to the PHP Chinese website!