CodeIgniter Study Notes (14) file upload in--ci

Source: Internet
Author: User
Tags codeigniter

First jump to the view by means of the controller

 Public function file ()
{    $this->load->helper (' url ');     $this->load->view (' file ');}

Create a form in the view to select and upload a file

<!DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <title>Document</title></Head><Body>    <formAction= "<?php echo site_url (' index.php/user/upload ');?>"Method= "POST"enctype= "Multipart/form-data">        <inputtype= "File"name= "Pic" />        <inputtype= "Submit"name= "Submit"value= "Submit">    </form></Body></HTML>

Note that the Name property of the first input, which is used after this property, is set to a controller method in the form, and the corresponding controller method is written

 Public functionupload () {//uploading files to the server directory    $config[' upload_path '] = './upload '; //What types are allowed to upload    $config[' allowed_types '] = ' gif|png|jpg|jpeg '; //file name after upload, with uniqid () to ensure the file name is unique    $config[' file_name '] =uniqid(); //loading the Upload library    $this->load->library (' Upload ',$config); //upload the file, where pic is the Name property of the document control in the view    $result=$this->upload->do_upload (' pic '); //If the upload is successful, get the information to upload the file    if($result)     {        Var_dump($this->upload->data ()); }}
This completes the file upload.

CodeIgniter Study Notes (14) file upload in--ci

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.