#1 2016-04-05 13:46:12

fever
Member
Registered: 2016-04-05
Posts: 7

How to add upload file or image field into module ?

I just want to lets admin upload a file or image from module that i created.
I tried to use Upload library but it's not work...

Thanks for your help

Offline

#2 2016-04-06 01:55:09

otemu
Member
Registered: 2014-03-07
Posts: 183

Re: How to add upload file or image field into module ?

Hi,

Can we see your code?

Offline

#3 2016-04-06 19:13:43

fever
Member
Registered: 2016-04-05
Posts: 7

Re: How to add upload file or image field into module ?

otemu wrote:

Hi,

Can we see your code?

Sorry I forgot to attach my code

all I want is Input Team Name , Tag , "Logo Image"
this is my views code

<?php
    $id = $id_team;
?>
<link rel="stylesheet" type="text/css" href="<?php echo base_url()."modules/teams/assets/css/team.css" ?>">

<form name="teamForm<?php echo $id ?>" id="teamForm<?php echo $id ?>" action="<?php echo admin_url() ?>module/teams/teams_management/save" enctype="multipart/form-data">
 
    <!-- Hidden fields -->
    <input id="id_team<?php echo $id ?>" name="id_team" type="hidden" value="<?php echo $id ?>" />

    <dl class="small">
        <dt>
            <label for="team_name<?php echo $id ?>"><?php echo "Name"?></label>
        </dt>
        <dd>
            <!--
            The validation of this mandatory field is first done by JS
            by adding the attribute data-validators="required"
            see : [url]http://mootools.net/docs/more/Forms/Form.Validator#Validators[/url]
            -->
            <input id="team_name<?php echo $id ?>" name="team_name" class="inputtext required" type="text" value="<?php echo $team_name ?>" data-validators="required" />
        </dd>
    </dl>
    <dl class="small">
        <dt>
            <label for="team_tag<?php echo $id ?>"><?php echo "Tag"?></label>
        </dt>
        <dd>
            <!--
            The validation of this mandatory field is first done by JS
            by adding the attribute data-validators="required"
            see : [url]http://mootools.net/docs/more/Forms/Form.Validator#Validators[/url]
            -->
            <input id="team_tag<?php echo $id ?>" name="team_tag" class="inputtext required" type="text" value="<?php echo $team_tag ?>" data-validators="required" />
        </dd>
    </dl>
    <dl class="small">
        <dt>
            <label for="team_logo<?php echo $id ?>"><?php echo "Logo"?></label>
        </dt>
        <dd>
            <input  id="team_logo<?php echo $id ?>" type="file" name="team_logo" >
            <?php if($id != '') { ?>
                <img id="team_img<?php echo $id ?>" src="<?php echo base_url()."modules/teams/assets/images/".$team_logo; ?>" width="100" height="100">
            <?php } ?>
        </dd>
    </dl>   
</form>
 
<!-- Save / Cancel buttons
   Must be named bSave[windows_id] where 'window_id' is the used ID
   or the window opening through ION.formWindow()
-->
<div class="buttons">
    <button id="bSaveteam<?php echo $id ?>" type="button" class="button yes right"><?php echo lang('ionize_button_save_close') ?></button>
    <button id="bCancelteam<?php echo $id ?>"  type="button" class="button no right"><?php echo lang('ionize_button_cancel') ?></button>
</div>
 
<script type="text/javascript">
 
    // Tabs init
    new TabSwapper({
        tabsContainer: 'teamTab<?php echo $id ?>',
        sectionsContainer: 'teamTabContent<?php echo $id ?>',
        selectedClass: 'selected',
        tabs: 'li',
        clickers: 'li a',
        sections: 'div.tabcontent<?php echo $id ?>'
    });
 
    // Autogrow textareas of the given form ID
    ION.initFormAutoGrow('teamForm<?php echo $id ?>');

</script>

and this is my save function in controller

public function save()
    {
        //The name must be set
        if ($this->input->post('team_name') != '')
        {
            // Upload img
            $dataset = array();
            $dataset = $this->input->post();
            //$filename = $_FILES['team_logo']['name'];
            $config['upload_path'] = admin_url().'module/teams/assets/images/';
            $config['allowed_types'] = 'png';
            $config['max_size']     = '20000';
            $config['max_width'] = '300';
            $config['max_height'] = '300';
            $config['file_ext_tolower'] = TRUE;
            $config['encrypt_name'] = FALSE;
            $config['overwrite'] = TRUE;
            $this->load->library('upload', $config);         
            $this->upload->initialize($config);
            $upload_field = "team_logo";

            if ( ! $this->upload->do_upload($upload_field))
            {
                $this->error($this->upload->display_errors());  
                $datapic= array('team_logo' => ''); 
                $dataset = array_merge($dataset, $datapic); 
            }
            else
            {
                $arr_csv = $this->upload->data();
                $datapic= array('team_logo' => $arr_csv['file_name']);
                $dataset = array_merge($dataset, $datapic); 
            }
            
            //$this->template['teams'] = $dataset;

            $id_match = $this->teams_model->save($dataset);
 
            // Update the authors list
            $this->update[] = array(
                'element' => 'moduleTeamsList',
                'url' => admin_url() . 'module/teams/teams_management/get_list'
            );
 
            // Send the user a message
            $this->success(lang('ionize_message_operation_ok'));
        }
        else
        {
            // Send the user a message
            $this->error(lang('ionize_message_operation_nok'));
        }
    }

Thank you for your help

Last edited by fever (2016-04-06 19:14:40)

Offline

#4 2016-04-07 11:22:09

adaliszk
Ionize Friend
From: Germany
Registered: 2010-09-20
Posts: 397
Website

Re: How to add upload file or image field into module ?

Hmm, Can you share the form submit request har file? (in chrome Network -> Request -> Right click -> Save as HAR)


Webdeveloper, Programmer, Application developer, Ionize friend
@adaliszk

Offline

#5 2016-04-07 11:56:23

fever
Member
Registered: 2016-04-05
Posts: 7

Re: How to add upload file or image field into module ?

adamos42 wrote:

Hmm, Can you share the form submit request har file? (in chrome Network -> Request -> Right click -> Save as HAR)

This is har file.
I am not sure, is this what you need or not ?
Please tell me if I did it wrong..
Thank you for your help.

 {
  "log": {
    "version": "1.2",
    "creator": {
      "name": "WebInspector",
      "version": "537.36"
    },
    "pages": [],
    "entries": [
      {
        "startedDateTime": "2016-04-07T08:55:45.312Z",
        "time": 322.9490000012447,
        "request": {
          "method": "POST",
          "url": "http://localhost/MyWeb/ionize/en/admin/module/teams/teams_management/get/2",
          "httpVersion": "HTTP/1.1",
          "headers": [
            {
              "name": "Cookie",
              "value": "webSettingsTab=0; settingsTab=0; ionizeSettingsTab=0; langTab=0; subnavTitleTab=0; metaDescriptionTab=0; metaKeywordsTab=0; mainTab=0; articleTab=1; articleMetaDescriptionTab=0; articleMetaKeywordsTab=0; PHPSESSID=5siul7e9rudjba83mdurp5dr13; shortcutBloc=false; modulesBloc=false; quickSettingsBloc=false; usersBloc=false; contentBloc=false; notificationBloc=false; dashBoardUsersTab=0; dashBoardContentTab=0"
            },
            {
              "name": "Origin",
              "value": "http://localhost"
            },
            {
              "name": "Accept-Encoding",
              "value": "gzip, deflate"
            },
            {
              "name": "Host",
              "value": "localhost"
            },
            {
              "name": "Accept-Language",
              "value": "en-US,en;q=0.8,th;q=0.6"
            },
            {
              "name": "User-Agent",
              "value": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36"
            },
            {
              "name": "Content-type",
              "value": "application/x-www-form-urlencoded; charset=UTF-8"
            },
            {
              "name": "Accept",
              "value": "text/javascript, text/html, application/xml, text/xml, */*"
            },
            {
              "name": "Referer",
              "value": "http://localhost/MyWeb/ionize/en/admin"
            },
            {
              "name": "X-Requested-With",
              "value": "XMLHttpRequest"
            },
            {
              "name": "Connection",
              "value": "keep-alive"
            },
            {
              "name": "Content-Length",
              "value": "0"
            }
          ],
          "queryString": [],
          "cookies": [
            {
              "name": "webSettingsTab",
              "value": "0",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "settingsTab",
              "value": "0",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "ionizeSettingsTab",
              "value": "0",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "langTab",
              "value": "0",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "subnavTitleTab",
              "value": "0",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "metaDescriptionTab",
              "value": "0",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "metaKeywordsTab",
              "value": "0",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "mainTab",
              "value": "0",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "articleTab",
              "value": "1",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "articleMetaDescriptionTab",
              "value": "0",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "articleMetaKeywordsTab",
              "value": "0",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "PHPSESSID",
              "value": "5siul7e9rudjba83mdurp5dr13",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "shortcutBloc",
              "value": "false",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "modulesBloc",
              "value": "false",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "quickSettingsBloc",
              "value": "false",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "usersBloc",
              "value": "false",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "contentBloc",
              "value": "false",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "notificationBloc",
              "value": "false",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "dashBoardUsersTab",
              "value": "0",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "dashBoardContentTab",
              "value": "0",
              "expires": null,
              "httpOnly": false,
              "secure": false
            }
          ],
          "headersSize": 992,
          "bodySize": 0
        },
        "response": {
          "status": 200,
          "statusText": "OK",
          "httpVersion": "HTTP/1.1",
          "headers": [
            {
              "name": "Pragma",
              "value": "no-cache"
            },
            {
              "name": "Date",
              "value": "Thu, 07 Apr 2016 08:55:45 GMT"
            },
            {
              "name": "Server",
              "value": "Apache/2.4.12 (Win32) OpenSSL/1.0.1l PHP/5.5.24"
            },
            {
              "name": "X-Powered-By",
              "value": "PHP/5.5.24"
            },
            {
              "name": "Content-Type",
              "value": "text/html; charset=UTF-8"
            },
            {
              "name": "Cache-Control",
              "value": "no-store, no-cache, must-revalidate"
            },
            {
              "name": "Cache-Control",
              "value": "post-check=0, pre-check=0"
            },
            {
              "name": "Connection",
              "value": "Keep-Alive"
            },
            {
              "name": "Keep-Alive",
              "value": "timeout=5, max=45"
            },
            {
              "name": "Content-Length",
              "value": "2571"
            },
            {
              "name": "Expires",
              "value": "Thu, 19 Nov 1981 08:52:00 GMT"
            }
          ],
          "cookies": [],
          "content": {
            "size": 2571,
            "mimeType": "text/html",
            "compression": 0,
            "text": "<link rel=\"stylesheet\" type=\"text/css\" href=\"http://localhost/MyWeb/ionize/modules/teams/assets/css/team.css\">\r\n\r\n<form name=\"teamForm2\" id=\"teamForm2\" action=\"http://localhost/MyWeb/ionize/admin/module/teams/teams_management/save\" enctype=\"multipart/form-data\">\r\n \r\n    <!-- Hidden fields -->\r\n    <input id=\"id_team2\" name=\"id_team\" type=\"hidden\" value=\"2\" />\r\n\r\n    <dl class=\"small\">\r\n        <dt>\r\n            <label for=\"team_name2\">Name</label>\r\n        </dt>\r\n        <dd>\r\n            <!--\r\n            The validation of this mandatory field is first done by JS\r\n            by adding the attribute data-validators=\"required\"\r\n            see : http://mootools.net/docs/more/Forms/Form.Validator#Validators\r\n            -->\r\n            <input id=\"team_name2\" name=\"team_name\" class=\"inputtext required\" type=\"text\" value=\"Natus Vincere\" data-validators=\"required\" />\r\n        </dd>\r\n    </dl>\r\n    <dl class=\"small\">\r\n        <dt>\r\n            <label for=\"team_tag2\">Tag</label>\r\n        </dt>\r\n        <dd>\r\n            <!--\r\n            The validation of this mandatory field is first done by JS\r\n            by adding the attribute data-validators=\"required\"\r\n            see : http://mootools.net/docs/more/Forms/Form.Validator#Validators\r\n            -->\r\n            <input id=\"team_tag2\" name=\"team_tag\" class=\"inputtext required\" type=\"text\" value=\"Na'Vi\" data-validators=\"required\" />\r\n        </dd>\r\n    </dl>\r\n    <dl class=\"small\">\r\n        <dt>\r\n            <label for=\"team_logo2\">Logo</label>\r\n        </dt>\r\n        <dd>\r\n            <input  id=\"team_logo2\" type=\"file\" name=\"team_logo\" >\r\n                            <img id=\"team_img2\" src=\"http://localhost/MyWeb/ionize/modules/teams/assets/images/navi.png\" width=\"100\" height=\"100\">\r\n                    </dd>\r\n    </dl>   \r\n</form>\r\n \r\n<!-- Save / Cancel buttons\r\n   Must be named bSave[windows_id] where 'window_id' is the used ID\r\n   or the window opening through ION.formWindow()\r\n-->\r\n<div class=\"buttons\">\r\n    <button id=\"bSaveteam2\" type=\"button\" class=\"button yes right\">Save & close</button>\r\n    <button id=\"bCancelteam2\"  type=\"button\" class=\"button no right\">Cancel</button>\r\n</div>\r\n \r\n<script type=\"text/javascript\">\r\n \r\n    // Tabs init\r\n    new TabSwapper({\r\n        tabsContainer: 'teamTab2',\r\n        sectionsContainer: 'teamTabContent2',\r\n        selectedClass: 'selected',\r\n        tabs: 'li',\r\n        clickers: 'li a',\r\n        sections: 'div.tabcontent2'\r\n    });\r\n \r\n    // Autogrow textareas of the given form ID\r\n    ION.initFormAutoGrow('teamForm2');\r\n\r\n</script>"
          },
          "redirectURL": "",
          "headersSize": 408,
          "bodySize": 2571,
          "_transferSize": 2979
        },
        "cache": {},
        "timings": {
          "blocked": 1.09800000063842,
          "dns": -1,
          "connect": -1,
          "send": 0.33400000393158,
          "wait": 317.027999997663,
          "receive": 4.488999999011696,
          "ssl": -1
        },
        "connection": "93820"
      },
      {
        "startedDateTime": "2016-04-07T08:55:48.210Z",
        "time": 379.9790000048233,
        "request": {
          "method": "POST",
          "url": "http://localhost/MyWeb/ionize/en/admin/module/teams/teams_management/save",
          "httpVersion": "HTTP/1.1",
          "headers": [
            {
              "name": "Cookie",
              "value": "webSettingsTab=0; settingsTab=0; ionizeSettingsTab=0; langTab=0; subnavTitleTab=0; metaDescriptionTab=0; metaKeywordsTab=0; mainTab=0; articleTab=1; articleMetaDescriptionTab=0; articleMetaKeywordsTab=0; PHPSESSID=5siul7e9rudjba83mdurp5dr13; shortcutBloc=false; modulesBloc=false; quickSettingsBloc=false; usersBloc=false; contentBloc=false; notificationBloc=false; dashBoardUsersTab=0; dashBoardContentTab=0"
            },
            {
              "name": "Origin",
              "value": "http://localhost"
            },
            {
              "name": "Accept-Encoding",
              "value": "gzip, deflate"
            },
            {
              "name": "Host",
              "value": "localhost"
            },
            {
              "name": "X-Request",
              "value": "JSON"
            },
            {
              "name": "User-Agent",
              "value": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36"
            },
            {
              "name": "Content-type",
              "value": "application/x-www-form-urlencoded; charset=UTF-8"
            },
            {
              "name": "Accept-Language",
              "value": "en-US,en;q=0.8,th;q=0.6"
            },
            {
              "name": "Accept",
              "value": "application/json"
            },
            {
              "name": "Referer",
              "value": "http://localhost/MyWeb/ionize/en/admin"
            },
            {
              "name": "X-Requested-With",
              "value": "XMLHttpRequest"
            },
            {
              "name": "Connection",
              "value": "keep-alive"
            },
            {
              "name": "Content-Length",
              "value": "50"
            }
          ],
          "queryString": [],
          "cookies": [
            {
              "name": "webSettingsTab",
              "value": "0",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "settingsTab",
              "value": "0",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "ionizeSettingsTab",
              "value": "0",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "langTab",
              "value": "0",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "subnavTitleTab",
              "value": "0",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "metaDescriptionTab",
              "value": "0",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "metaKeywordsTab",
              "value": "0",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "mainTab",
              "value": "0",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "articleTab",
              "value": "1",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "articleMetaDescriptionTab",
              "value": "0",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "articleMetaKeywordsTab",
              "value": "0",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "PHPSESSID",
              "value": "5siul7e9rudjba83mdurp5dr13",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "shortcutBloc",
              "value": "false",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "modulesBloc",
              "value": "false",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "quickSettingsBloc",
              "value": "false",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "usersBloc",
              "value": "false",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "contentBloc",
              "value": "false",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "notificationBloc",
              "value": "false",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "dashBoardUsersTab",
              "value": "0",
              "expires": null,
              "httpOnly": false,
              "secure": false
            },
            {
              "name": "dashBoardContentTab",
              "value": "0",
              "expires": null,
              "httpOnly": false,
              "secure": false
            }
          ],
          "headersSize": 967,
          "bodySize": 50,
          "postData": {
            "mimeType": "application/x-www-form-urlencoded; charset=UTF-8",
            "text": "id_team=2&team_name=Natus%20Vincere&team_tag=Na'Vi",
            "params": [
              {
                "name": "id_team",
                "value": "2"
              },
              {
                "name": "team_name",
                "value": "Natus%20Vincere"
              },
              {
                "name": "team_tag",
                "value": "Na'Vi"
              }
            ]
          }
        },
        "response": {
          "status": 200,
          "statusText": "OK",
          "httpVersion": "HTTP/1.1",
          "headers": [
            {
              "name": "Pragma",
              "value": "no-cache"
            },
            {
              "name": "Date",
              "value": "Thu, 07 Apr 2016 08:55:48 GMT"
            },
            {
              "name": "Server",
              "value": "Apache/2.4.12 (Win32) OpenSSL/1.0.1l PHP/5.5.24"
            },
            {
              "name": "X-Powered-By",
              "value": "PHP/5.5.24"
            },
            {
              "name": "Content-Type",
              "value": "text/html"
            },
            {
              "name": "Cache-Control",
              "value": "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
            },
            {
              "name": "Connection",
              "value": "Keep-Alive"
            },
            {
              "name": "Keep-Alive",
              "value": "timeout=5, max=43"
            },
            {
              "name": "Content-Length",
              "value": "694"
            },
            {
              "name": "Expires",
              "value": "Thu, 19 Nov 1981 08:52:00 GMT"
            }
          ],
          "cookies": [],
          "content": {
            "size": 694,
            "mimeType": "text/html",
            "compression": 0,
            "text": "<div style=\"border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;\">\n\n<h4 style=\"color:#c00;\">A PHP Error was encountered</h4>\n\n<p>Severity: Warning</p>\n<p>Message:  Invalid argument supplied for foreach()</p>\n<p>Filename: libraries/MY_Upload.php</p>\n<p>Line Number: 243</p>\n\n</div><div style=\"border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;\">\n\n<h4 style=\"color:#c00;\">A PHP Error was encountered</h4>\n\n<p>Severity: Notice</p>\n<p>Message:  Undefined index: X-File-Name</p>\n<p>Filename: libraries/MY_Upload.php</p>\n<p>Line Number: 657</p>\n\n</div>{\"message_type\":\"error\",\"message\":\"<p>The filetype you are attempting to upload is not allowed.<\\/p>\",\"update\":[],\"callback\":[]}"
          },
          "redirectURL": "",
          "headersSize": 377,
          "bodySize": 694,
          "_transferSize": 1071
        },
        "cache": {},
        "timings": {
          "blocked": 1.23200000234647,
          "dns": -1,
          "connect": -1,
          "send": 0.4180000032647502,
          "wait": 377.5359999999638,
          "receive": 0.792999999248309,
          "ssl": -1
        },
        "connection": "93820"
      }
    ]
  }
} 

Last edited by fever (2016-04-07 11:58:08)

Offline

#6 2016-04-07 12:19:02

fever
Member
Registered: 2016-04-05
Posts: 7

Re: How to add upload file or image field into module ?

I found this when I used "Inspenct Element -> Network -> Preview"

A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: libraries/MY_Upload.php

Line Number: 243

A PHP Error was encountered

Severity: Notice

Message: Undefined index: X-File-Name

Filename: libraries/MY_Upload.php

Line Number: 657

{"message_type":"error","message":"
The filetype you are attempting to upload is not allowed.<\/p>","update":[],"callback":[]}

and In Line: 243 I found that It is inside a

public function before_upload_initialization($config = array()){
		// Forbidden before upload config key
		$forbidden = array(
			'document_root',
			'safe'
		);

		foreach ($config as $key => $val)
		{
			// if (isset($this->{$key}) && ! in_array($key, $forbidden))
			if (isset($this->{$key}) && ! in_array($key, $forbidden))
			{
				$this->$key = $config[$key];

				if ($key == 'upload_path')
					$this->upload_path = $this->normalize($this->document_root . $this->upload_path);
			}
		}
	}

and this

 public function do_upload($config = array())
	{
		// Sets the config before one upload (useful if some config element has to be set without reloading the lib)
		if ( ! empty($config))
			$this->before_upload_initialization($config);

		if ($this->is_HTML5_upload($config))
		{
			return $this->HTML5_upload($config);
		}
		else
		{
			return $this->HTML4_upload($config);
		}
	} 

but I am using do_upload function like this

  $upload_field = "team_logo";

            if ( ! $this->upload->do_upload($upload_field))
            {
                $this->error($this->upload->display_errors());  
                $datapic= array('team_logo' => ''); 
                $dataset = array_merge($dataset, $datapic); 
            }
            else
            {
                $arr_csv = $this->upload->data();
                $datapic= array('team_logo' => $arr_csv['file_name']);
                $dataset = array_merge($dataset, $datapic); 
            } 

I think It's wrong because of parameter that I sent to function is a string... So, my question is "How $config should be ?"

Thank you for your help.

Offline

#7 2016-04-07 20:45:07

otemu
Member
Registered: 2014-03-07
Posts: 183

Re: How to add upload file or image field into module ?

Hi,

I experience a similar error when uploading

instead of using:

$config['allowed_types']

use:

$config['allowed_extensions'] = array('png');

Offline

#8 2016-04-08 08:12:51

fever
Member
Registered: 2016-04-05
Posts: 7

Re: How to add upload file or image field into module ?

@otemu

Hi,

Could you please make a simple example for me ?

I still getting this error

A PHP Error was encountered

Severity: Notice

Message: Undefined index: X-File-Name

Filename: libraries/MY_Upload.php

Line Number: 657

Offline

#9 2016-04-09 18:27:37

otemu
Member
Registered: 2014-03-07
Posts: 183

Re: How to add upload file or image field into module ?

Hi,

Here is quick example for you

FORM CONFIG

'fileupload' => array
(
    'process' => 'TagManager_User::process_data',
    // Redirection after process. Can be 'home' or 'referer' for the $_SERVER['HTTP_REFERER'] value.
    // If not set, doesn't redirect
    'redirect' => 'referer',
    // Message Language index, as set in language/xx/form_lang.php
    'messages' => array
    (
        'success' => 'form_success',
        'error' => 'form_error',
    ),
    'fields' => array
    (
        'userfile' => array(
            // CI rules
            'rules' => 'required',
            // Label translated index, as set in language/xx/form_lang.php
            // Will be used to display the label name in error messages
            'label' => 'form_label',
        )
    )
),

VIEW

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<title>Title</title>
	</head>
	<body>
		<form method="post" action="" enctype="multipart/form-data"> 
			<input type="hidden" name="form" value="fileupload" />	
			<input type="file" name="userfile" />
			<input type="submit" name="submit" value="upload"/>   				
		</form>
	</body>
</html>

FORM PROCESS:

case 'fileupload':
    if (TagManager_Form::validate('fileupload'))
    {    
		$config['upload_path'] = "your upload path";
		$config['allowed_extensions'] = array('gif', 'jpg', 'png');
		$config['overwrite'] = true;
		
		self::$ci->load->library('upload', $config);             

		if ( ! self::$ci->upload->do_upload())
		{
			//upload failed
			var_dump(self::$ci->upload->display_errors());
		}
		else
		{		
			//upload passed
			echo "worked";	
			var_dump(self::$ci->upload->data());
		}
    }	 				
break;

Offline

What's Ionize ?

Ionize is an Open Source Content Management System created by webdesigners for webdesigners.

Created and maintained by Partikule and Toopixel, Ionize wants to be the easiest and most powerful CMS.

Can I help ?

Because talent is nothing without involvement, we are looking for motivated coders and webdesigners to join the project team.

Resources

Website : ionizecms.com
Documentation : doc.ionizecms.com

Development : Ionize on GitHub
Translations : Ionize Translations