pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    • <bdo id='U2CDY'></bdo><ul id='U2CDY'></ul>
    <i id='U2CDY'><tr id='U2CDY'><dt id='U2CDY'><q id='U2CDY'><span id='U2CDY'><b id='U2CDY'><form id='U2CDY'><ins id='U2CDY'></ins><ul id='U2CDY'></ul><sub id='U2CDY'></sub></form><legend id='U2CDY'></legend><bdo id='U2CDY'><pre id='U2CDY'><center id='U2CDY'></center></pre></bdo></b><th id='U2CDY'></th></span></q></dt></tr></i><div class="e2soqmk" id='U2CDY'><tfoot id='U2CDY'></tfoot><dl id='U2CDY'><fieldset id='U2CDY'></fieldset></dl></div>
      <legend id='U2CDY'><style id='U2CDY'><dir id='U2CDY'><q id='U2CDY'></q></dir></style></legend>

        <tfoot id='U2CDY'></tfoot>

        <small id='U2CDY'></small><noframes id='U2CDY'>

      1. Codeigniter 中的文件上傳驗證

        File Upload Validation In Codeigniter(Codeigniter 中的文件上傳驗證)
      2. <legend id='LlOek'><style id='LlOek'><dir id='LlOek'><q id='LlOek'></q></dir></style></legend>
          <tbody id='LlOek'></tbody>

          <tfoot id='LlOek'></tfoot>

          <small id='LlOek'></small><noframes id='LlOek'>

        • <i id='LlOek'><tr id='LlOek'><dt id='LlOek'><q id='LlOek'><span id='LlOek'><b id='LlOek'><form id='LlOek'><ins id='LlOek'></ins><ul id='LlOek'></ul><sub id='LlOek'></sub></form><legend id='LlOek'></legend><bdo id='LlOek'><pre id='LlOek'><center id='LlOek'></center></pre></bdo></b><th id='LlOek'></th></span></q></dt></tr></i><div class="kiokgw0" id='LlOek'><tfoot id='LlOek'></tfoot><dl id='LlOek'><fieldset id='LlOek'></fieldset></dl></div>

                  <bdo id='LlOek'></bdo><ul id='LlOek'></ul>
                • 本文介紹了Codeigniter 中的文件上傳驗證的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我正在嘗試驗證圖片上傳的文件上傳,但它沒有像其他字段一樣得到驗證.我正在使用 Form_Validation.php 過程進(jìn)行驗證.

                  I am trying to validate file upload for image uploading, but it is not getting the validation like other fields. I am using Form_Validation.php process for validation.

                  圖片上傳數(shù)組:

                  array(
                              'field'=>'image',
                              'label' => 'Image',
                              'rules' => 'required'
                          )
                  

                  當(dāng)我嘗試上傳圖像時,它沒有像需要等那樣響應(yīng).我還想驗證它的 .jpg 等以及如何在不正確的文件上設(shè)置文件值,例如.jpg 我們嘗試上傳 .pdf" 就像我們設(shè)置輸入字段的值 set_value('field name') 等.

                  when i try to upload the image it did not response like it is required etc. I also want to validate it for .jpg etc and "how to set the file value on incorrect file like instead of .jpg we try to upload the .pdf" like we set the value of input field set_value('field name') etc.

                  我查了很多問題,也嘗試使用call方法,但沒能解決.

                  I checked a lot of questions and also try to use call method, but did not able to fix it.

                  更新:

                  請?zhí)峁в写a示例的詳細(xì)答案.請在示例中使用 form_validation.php 方式并提供回調(diào)示例代碼,以便我可以閱讀/學(xué)習(xí)并相應(yīng)地修改它.

                  Please provide detail answer with code example. Please use the form_validation.php way in example and also provide the callback example code, so i can read / learn and modify it accordingly.

                  更新 2:

                   public function Task()
                      {
                          if ($this->form_validation->run('Sub_Admin/task') == FALSE) {
                              $this->data['Task'] = $this->bm->get_usr();
                              $data['title'] = "Add New Task";
                              $this->load->view('Subadmin/header',$data);
                              $this->load->view('Subadmin/nav');
                              $this->load->view('Subadmin/sidebar');
                              $this->load->view('Subadmin/task', $this->data);
                              $this->load->view('Subadmin/footer');
                          }
                          else
                          {
                  
                              $config['upload_path'] = './taskimages/'; //The path where the image will be save
                              $config['allowed_types'] = 'gif|jpg|png'; //Images extensions accepted
                              $config['max_size'] ='10048'; //The max size of the image in kb's
                              //$config['max_width']  = '1024'; //The max of the images width in px
                              //$config['max_height']  = '768'; //The max of the images height in px
                              $config['overwrite'] = FALSE; //If exists an image with the same name it will overwrite. Set to false if don't want to overwrite
                              $this->load->library('upload', $config); //Load the upload CI library
                              $this->load->initialize($config);
                              $this->upload->do_upload('task');
                              $file_info = $this->upload->data();
                              $file_name = $file_info['file_name'];
                              $data = array(
                                  'Job_Title' => $this->input->post('jtitle'),
                                  'Priority' => $this->input->post('jnature'),
                                  'Assignee' => $this->input->post('assigne'),
                                  'Employee_Name' => $this->input->post('assignto'),
                                  'Due_Date' => $this->input->post('ddate'),
                                  'Reminder' => $this->input->post('reminder'),
                                  'Task_Image' => $file_name,
                              );
                  
                              $this->bm->add_task($data);
                  
                          }
                      }
                  

                  我已經(jīng)在使用 CI 上傳類但它不起作用,現(xiàn)在我想從 form_validation 端驗證圖像/文件.

                  推薦答案

                  我為你的問題寫了一個完整的例子,希望對你有所幫助.在以下代碼中,我使用了 CI 的表單驗證回調(diào)和表單驗證自定義錯誤消息.

                  I wrote a complete example for your problem, I hope it will help. In the following code I am using CI's Form validation callback and Form Validation Custom Error Messages.

                  控制器: Front.php

                  Controller: Front.php

                  class Front 擴展 CI_Controller {

                  class Front extends CI_Controller {

                  public function index() {
                      $this->load->view('form');
                  }
                  
                  public function upload_image() {
                      $this->load->library('form_validation');
                      if ($this->form_validation->run('user_data') == FALSE) {
                          $this->load->view('form');
                      }
                      else {
                          echo 'You form Submitted Successfully ';
                      }
                  }
                  
                  public function validate_image() {
                      $check = TRUE;
                      if ((!isset($_FILES['my_image'])) || $_FILES['my_image']['size'] == 0) {
                          $this->form_validation->set_message('validate_image', 'The {field} field is required');
                          $check = FALSE;
                      }
                      else if (isset($_FILES['my_image']) && $_FILES['my_image']['size'] != 0) {
                          $allowedExts = array("gif", "jpeg", "jpg", "png", "JPG", "JPEG", "GIF", "PNG");
                          $allowedTypes = array(IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF);
                          $extension = pathinfo($_FILES["my_image"]["name"], PATHINFO_EXTENSION);
                          $detectedType = exif_imagetype($_FILES['my_image']['tmp_name']);
                          $type = $_FILES['my_image']['type'];
                          if (!in_array($detectedType, $allowedTypes)) {
                              $this->form_validation->set_message('validate_image', 'Invalid Image Content!');
                              $check = FALSE;
                          }
                          if(filesize($_FILES['my_image']['tmp_name']) > 2000000) {
                              $this->form_validation->set_message('validate_image', 'The Image file size shoud not exceed 20MB!');
                              $check = FALSE;
                          }
                          if(!in_array($extension, $allowedExts)) {
                              $this->form_validation->set_message('validate_image', "Invalid file extension {$extension}");
                              $check = FALSE;
                          }
                      }
                      return $check;
                  }
                  

                  }

                  查看: form.php

                  <!DOCTYPE html>
                  <html>
                  <head>
                      <title>Image Upload</title>
                  </head>
                  <body>
                      <h1><a href="<?= base_url() ?>">Form</a></h1>
                      <?php if(!empty(validation_errors())): ?>
                          <p><?= validation_errors() ?></p>
                      <?php endif; ?>
                      <?= form_open('front/upload_image', ['enctype' => "multipart/form-data"]) ?>
                      <label>Name: </label><input type="text" name="name" value="<?= set_value('name') ?>"></label>
                      <label>E-mail: </label><input type="email" name="email" value="<?= set_value('email') ?>"></label>
                      <input type="file" name="my_image">
                      <button type="submit">Submit</button>
                      <?= form_close() ?>
                  </body>
                  </html>
                  

                  form_validation.php

                  $config = array(
                          'user_data' => array(
                                  array(
                                          'field' => 'name',
                                          'label' => 'Name',
                                          'rules' => 'trim|required'
                                  ),
                                  array(
                                          'field' => 'email',
                                          'label' => 'Email',
                                          'rules' => 'trim|required|valid_email'
                                  ),
                                  array(
                                          'field' => 'my_image',
                                          'label' => 'Image',
                                          'rules' => 'callback_validate_image'
                                  )
                          )
                  );
                  

                  在上面的例子中,首先我驗證了 nameemail 并且對于圖像我調(diào)用了 validate_image 函數(shù)來驗證它,因為form_validation 庫不提供圖像驗證,但我有回調(diào)來進(jìn)行自定義驗證,validate_image 將檢查圖像內(nèi)容類型,然后檢查圖像文件大小,然后檢查圖像擴展名,如果沒有滿足任何這些要求,它會使用 form_validation 庫的 set_message() 函數(shù)為每個需求設(shè)置錯誤消息.

                  In above example first I am validating the name and email and for the Image I am calling the validate_image function to validate it, since form_validation library does not provide image validation but i has callbacks to do custom validations, the validate_image will check image content type then check image file size and then check image extension if any of these requirements are not fulfilled it will set error message for each requirement using set_message() function of form_validation library.

                  這篇關(guān)于Codeigniter 中的文件上傳驗證的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  enable SOAP on PHP(在 PHP 上啟用 SOAP)
                  Get received XML from PHP SOAP Server(從 PHP SOAP 服務(wù)器獲取接收到的 XML)
                  not a valid AllXsd value(不是有效的 AllXsd 值)
                  PHP SoapClient: SoapFault exception Could not connect to host(PHP SoapClient:SoapFault 異常無法連接到主機)
                  Implementation of P_SHA1 algorithm in PHP(PHP中P_SHA1算法的實現(xiàn))
                  Sending a byte array from PHP to WCF(將字節(jié)數(shù)組從 PHP 發(fā)送到 WCF)
                      <tbody id='H3S9c'></tbody>
                        • <bdo id='H3S9c'></bdo><ul id='H3S9c'></ul>
                          <tfoot id='H3S9c'></tfoot>

                          <small id='H3S9c'></small><noframes id='H3S9c'>

                          <legend id='H3S9c'><style id='H3S9c'><dir id='H3S9c'><q id='H3S9c'></q></dir></style></legend>

                        • <i id='H3S9c'><tr id='H3S9c'><dt id='H3S9c'><q id='H3S9c'><span id='H3S9c'><b id='H3S9c'><form id='H3S9c'><ins id='H3S9c'></ins><ul id='H3S9c'></ul><sub id='H3S9c'></sub></form><legend id='H3S9c'></legend><bdo id='H3S9c'><pre id='H3S9c'><center id='H3S9c'></center></pre></bdo></b><th id='H3S9c'></th></span></q></dt></tr></i><div class="ywo00qc" id='H3S9c'><tfoot id='H3S9c'></tfoot><dl id='H3S9c'><fieldset id='H3S9c'></fieldset></dl></div>
                            主站蜘蛛池模板: 巨野月嫂-家政公司-巨野县红墙安康母婴护理中心 | 高压绝缘垫-红色配电房绝缘垫-绿色高压绝缘地毯-上海苏海电气 | 三价铬_环保铬_环保电镀_东莞共盈新材料贸易有限公司 | 对辊式破碎机-对辊制砂机-双辊-双齿辊破碎机-巩义市裕顺机械制造有限公司 | 液氮罐_液氮容器_自增压液氮罐-北京君方科仪科技发展有限公司 | 标准品网_标准品信息网_【中检计量】 | 齿轮减速机电机一体机_齿轮减速箱加电机一体化-德国BOSERL蜗轮蜗杆减速机电机生产厂家 | 橡胶膜片,夹布膜片,橡胶隔膜密封,泵阀设备密封膜片-衡水汉丰橡塑科技公司网站 | 拖链电缆_柔性电缆_伺服电缆_坦克链电缆-深圳市顺电工业电缆有限公司 | Dataforth隔离信号调理模块-信号放大模块-加速度振动传感器-北京康泰电子有限公司 | 天津试验仪器-电液伺服万能材料试验机,恒温恒湿标准养护箱,水泥恒应力压力试验机-天津鑫高伟业科技有限公司 | 临沂招聘网_人才市场_招聘信息_求职招聘找工作请认准【马头商标】 | 反渗透阻垢剂-缓蚀阻垢剂厂家-循环水处理药剂-山东鲁东环保科技有限公司 | 超声波焊接机,振动摩擦焊接机,激光塑料焊接机,超声波焊接模具工装-德召尼克(常州)焊接科技有限公司 | 口信网(kousing.com) - 行业资讯_行业展会_行业培训_行业资料 | 高压分散机(高压细胞破碎仪)百科-北京天恩瀚拓 | 山东限矩型液力偶合器_液力耦合器易熔塞厂家-淄博市汇川源机械厂 | 红立方品牌应急包/急救包加盟,小成本好项目代理_应急/消防/户外用品加盟_应急好项目加盟_新奇特项目招商 - 中红方宁(北京) 供应链有限公司 | 武汉创亿电气设备有限公司_电力检测设备生产厂家 | 电动百叶窗,开窗器,电动遮阳百叶,电动开窗机生产厂家-徐州鑫友工控科技发展有限公司 | 临海涌泉蜜桔官网|涌泉蜜桔微商批发代理|涌泉蜜桔供应链|涌泉蜜桔一件代发 | 哈尔滨京科脑康神经内科医院-哈尔滨治疗头痛医院-哈尔滨治疗癫痫康复医院 | 杭州标识标牌|文化墙|展厅|导视|户内外广告|发光字|灯箱|铭阳制作公司 - 杭州标识标牌|文化墙|展厅|导视|户内外广告|发光字|灯箱|铭阳制作公司 | 硬质合金模具_硬质合金非标定制_硬面加工「生产厂家」-西迪技术股份有限公司 | 阜阳在线-阜阳综合门户 | 数码听觉统合训练系统-儿童感觉-早期言语评估与训练系统-北京鑫泰盛世科技发展有限公司 | 插针变压器-家用电器变压器-工业空调变压器-CD型电抗器-余姚市中驰电器有限公司 | 高光谱相机-近红外高光谱相机厂家-高光谱成像仪-SINESPEC 赛斯拜克 | 定制液氮罐_小型气相液氮罐_自增压液氮罐_班德液氮罐厂家 | 胶辊硫化罐_胶鞋硫化罐_硫化罐厂家-山东鑫泰鑫智能装备有限公司 意大利Frascold/富士豪压缩机_富士豪半封闭压缩机_富士豪活塞压缩机_富士豪螺杆压缩机 | 武汉EPS线条_EPS装饰线条_EPS构件_湖北博欧EPS线条厂家 | 活性炭-蜂窝-椰壳-柱状-粉状活性炭-河南唐达净水材料有限公司 | 驾驶人在线_专业学车门户网站 | 磁力抛光机_磁力研磨机_磁力去毛刺机_精密五金零件抛光设备厂家-冠古科技 | 金蝶帐无忧|云代账软件|智能财税软件|会计代账公司专用软件 | 工程管道/塑料管材/pvc排水管/ppr给水管/pe双壁波纹管等品牌管材批发厂家-河南洁尔康建材 | 宜兴紫砂壶知识分享 - 宜兴壶人| 知企服务-企业综合服务(ZiKeys.com)-品优低价、种类齐全、过程管理透明、速度快捷高效、放心服务,知企专家! | 塑料瓶罐_食品塑料瓶_保健品塑料瓶_调味品塑料瓶–东莞市富慷塑料制品有限公司 | 一路商机网-品牌招商加盟优选平台-加盟店排行榜平台 | ORP控制器_ORP电极价格-上优泰百科 |