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

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

      <legend id='QtV0y'><style id='QtV0y'><dir id='QtV0y'><q id='QtV0y'></q></dir></style></legend>
        <bdo id='QtV0y'></bdo><ul id='QtV0y'></ul>
    1. <tfoot id='QtV0y'></tfoot>

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

        如何在數據庫中保存上傳文件的名稱

        How to Save Uploaded File#39;s Name on Database(如何在數據庫中保存上傳文件的名稱)

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

            <tfoot id='OWQZp'></tfoot>
              <bdo id='OWQZp'></bdo><ul id='OWQZp'></ul>
              <legend id='OWQZp'><style id='OWQZp'><dir id='OWQZp'><q id='OWQZp'></q></dir></style></legend>

                  <tbody id='OWQZp'></tbody>
                • <i id='OWQZp'><tr id='OWQZp'><dt id='OWQZp'><q id='OWQZp'><span id='OWQZp'><b id='OWQZp'><form id='OWQZp'><ins id='OWQZp'></ins><ul id='OWQZp'></ul><sub id='OWQZp'></sub></form><legend id='OWQZp'></legend><bdo id='OWQZp'><pre id='OWQZp'><center id='OWQZp'></center></pre></bdo></b><th id='OWQZp'></th></span></q></dt></tr></i><div class="giq0kq0" id='OWQZp'><tfoot id='OWQZp'></tfoot><dl id='OWQZp'><fieldset id='OWQZp'></fieldset></dl></div>
                • 本文介紹了如何在數據庫中保存上傳文件的名稱的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  繼續.- 將文件上傳器添加到 Joomla 管理組件>

                  我可以上傳文件并將其保存在磁盤上.但它沒有在數據庫中保存文件名.

                  我該怎么做?

                  這是控制器 -

                  class InvoiceManagerControllerInvoiceManager 擴展 JControllerForm{函數保存(){$file = JRequest::getVar('jform', null, 'files', 'array');$path = JPATH_BASE;//確保文件名安全.jimport('joomla.filesystem.file');$file['name']['invoice'] = JFile::makeSafe($file['name']['invoice']);//將上傳的文件移動到一個永久位置.if (isset($file['name']['invoice'])) {//確保完整的文件路徑是安全的.$filepath = JPath::clean($path.DS."components".DS."com_invoicemanager".DS."files".DS.strtolower($file['name']['invoice']));//移動上傳的文件.JFile::upload( $file['tmp_name']['invoice'], $filepath );}返回父級::保存();}}

                  XML 中的表單字段 -

                  更新:添加以下來自@Andras Gera 代碼的行后工作

                  $data = JRequest::getVar('jform', null, 'post', 'array');$data['invoice'] = strtolower( $file['name']['invoice'] );JRequest::setVar('jform', $data );

                  解決方案

                  我也遇到了同樣的問題,也許我們可以一起前進.這是我的代碼:

                  /administrator/components/com_comp_name/models/forms/edit.xml

                  <選項value="1">JPUBLISHED</option><選項value="0">JUNPUBLISHED</option></field><字段類型=文件"名稱="pdf_file"標簽="COM_GONEWSLETTER_EDIT_FILE_LABEL"默認="描述="COM_GONEWSLETTER_EDIT_FILE_DESC"大小=40"接受=申請/pdf"類=文件上傳器"/><字段名稱=文件"類型=隱藏"/></fieldset></表單>

                  和/administrator/components/com_comp_name/controllers/edit.php

                  view_list = '列表';parent::__construct($config);}函數保存(){//--------------------- 上傳文件 ---------------------//必要的庫和變量jimport('joomla.filesystem.folder');jimport('joomla.filesystem.file');$data = JRequest::getVar('jform', null, 'post', 'array');//如果圖像文件夾中不存在 gonewsleter 文件夾,則創建該文件夾if ( !JFolder::exists( JPATH_SITE . DS . "images" . DS . "gonewsletter" ) ) {JFolder::create( JPATH_SITE . DS . "images" . DS . "gonewsletter" );}//從請求中獲取文件數據數組.$file = JRequest::getVar('jform', null, 'files', 'array');//確保文件名安全.$filename = JFile::makeSafe($file['name']['pdf_file']);//將上傳的文件移動到一個永久位置.如果($文件名!= ''){//確保完整的文件路徑是安全的.$filepath = JPath::clean( JPATH_SITE . DS . 'images' . DS . 'gonewsletter' . DS . strtolower( $filename ) );//移動上傳的文件.JFile::upload( $file['tmp_name']['pdf_file'], $filepath );//在保存到數據庫之前更改 $data['file'] 值$data['file'] = strtolower( $filename );}//--------------------- 文件上傳結束 ------------------------JRequest::setVar('jform', $data );返回父級::保存();}}

                  如果您在將 $data 發送到 parent::save($data) 之前打印它,它包含您想要保存的正確字段,但它沒有.我嘗試使用輸入 type=text 而不是 type=file 并正確保存.

                  我嘗試了另一種方式,例如:輸入類型=文件和名稱=pdf_file,然后我添加了一個隱藏字段名稱=文件默認=".然后我將此隱藏字段值設置為文件名但沒有成功.也許我做錯了什么.繼續想辦法.

                  Cont. - Add File Uploader to Joomla Admin Component

                  I could able to upload file and save it on disk. But its not saving file name on the database.

                  How can i do it ?

                  Here is the controller -

                  class InvoiceManagerControllerInvoiceManager extends JControllerForm
                  {
                      function save(){
                          $file = JRequest::getVar('jform', null, 'files', 'array');
                          $path = JPATH_BASE;
                  
                          // Make the file name safe.
                          jimport('joomla.filesystem.file');
                          $file['name']['invoice'] = JFile::makeSafe($file['name']['invoice']);
                  
                          // Move the uploaded file into a permanent location.
                          if (isset($file['name']['invoice'])) {
                              // Make sure that the full file path is safe.
                              $filepath = JPath::clean($path. DS ."components". DS ."com_invoicemanager". DS ."files". DS .strtolower($file['name']['invoice']));
                              // Move the uploaded file.
                              JFile::upload( $file['tmp_name']['invoice'], $filepath );
                          }
                  
                          return parent::save();
                      }
                  }
                  

                  Form field in XML -

                  <field name="invoice" type="file"/>
                  

                  UPDATE: worked after adding following lines taken from @Andras Gera code

                  $data = JRequest::getVar( 'jform', null, 'post', 'array' );
                  $data['invoice'] = strtolower( $file['name']['invoice'] );
                  
                  JRequest::setVar('jform', $data );
                  

                  解決方案

                  I've ran into the same problem, maybe we can go forward together. Here is my codes:

                  /administrator/components/com_comp_name/models/forms/edit.xml

                  <?xml version="1.0" encoding="utf-8"?>
                  <form addrulepath="/administrator/components/com_gonewsletter/models/rules">
                      <fieldset name="details">
                          <field
                              name="id"
                              type="hidden"
                          />
                          <field
                              name="title"
                              type="text"
                              label="COM_GONEWSLETTER_EDIT_TITLE_LABEL"
                              description="COM_GONEWSLETTER_EDIT_TITLE_DESC"
                              size="40"
                              class="inputbox"
                              required="true"
                              default=""
                          />
                          <field
                              name="date"
                              type="calendar"
                              label="COM_GONEWSLETTER_EDIT_DATE_LABEL"
                              description="COM_GONEWSLETTER_EDIT_DATE_DESC"
                              size="40"
                              class="inputbox"
                              required="true"
                              default=""
                              format="%Y-%m-%d"
                          />
                          <field
                              name="published"
                              type="list"
                              label="JSTATUS"
                              description="COM_GONEWSLETTER_EDIT_PUBLISHED_DESC"
                              class="inputbox"
                              size="1"
                              default="0">
                              <option
                                  value="1">JPUBLISHED</option>
                              <option
                                  value="0">JUNPUBLISHED</option>
                          </field>
                          <field
                              type="file"
                              name="pdf_file"
                              label="COM_GONEWSLETTER_EDIT_FILE_LABEL"
                              default=""
                              description="COM_GONEWSLETTER_EDIT_FILE_DESC"
                              size="40"
                              accept="application/pdf"
                              class="fileuploader"
                          />
                          <field
                              name="file"
                              type="hidden"
                          />
                      </fieldset>
                  </form>
                  

                  and /administrator/components/com_comp_name/controllers/edit.php

                  <?php
                  // No direct access to this file
                  defined('_JEXEC') or die('Restricted access');
                  
                  // import Joomla controllerform library
                  jimport('joomla.application.component.controllerform');
                  
                  /**
                   * GoNewsletter Controller
                   */
                  class GoNewsletterControllerEdit extends JControllerForm
                  {
                      function __construct($config = array()) {
                          $this->view_list = 'List';
                          parent::__construct($config);
                      }
                  
                      function save(){
                          // ---------------------------- Uploading the file ---------------------
                          // Neccesary libraries and variables
                          jimport( 'joomla.filesystem.folder' );
                          jimport('joomla.filesystem.file');
                          $data = JRequest::getVar( 'jform', null, 'post', 'array' );
                  
                          // Create the gonewsleter folder if not exists in images folder
                          if ( !JFolder::exists( JPATH_SITE . DS . "images" . DS . "gonewsletter" ) ) {
                              JFolder::create( JPATH_SITE . DS . "images" . DS . "gonewsletter" );
                          }
                  
                          // Get the file data array from the request.
                          $file = JRequest::getVar( 'jform', null, 'files', 'array' );
                  
                          // Make the file name safe.
                          $filename = JFile::makeSafe($file['name']['pdf_file']);
                  
                          // Move the uploaded file into a permanent location.
                          if ( $filename != '' ) {
                              // Make sure that the full file path is safe.
                              $filepath = JPath::clean( JPATH_SITE . DS . 'images' . DS . 'gonewsletter' . DS . strtolower( $filename ) );
                  
                              // Move the uploaded file.
                              JFile::upload( $file['tmp_name']['pdf_file'], $filepath );
                              // Change $data['file'] value before save into the database 
                              $data['file'] = strtolower( $filename );
                          }
                          // ---------------------------- File Upload Ends ------------------------
                  
                          JRequest::setVar('jform', $data );
                  
                          return parent::save();
                      }
                  
                  }
                  

                  If you print out the $data before send it to parent::save($data) it contains the right fields you want to save, but it doesn't. I tried to use an input type=text instead of type=file and it saves correctly.

                  I tried another way like: input type=file and name=pdf_file, after then I added a hidden field name=file default="". And then I've set up this hidden field value to filename without success. Maybe I was doing something wrong. Keep continue to figure out something.

                  這篇關于如何在數據庫中保存上傳文件的名稱的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  enable SOAP on PHP(在 PHP 上啟用 SOAP)
                  Get received XML from PHP SOAP Server(從 PHP SOAP 服務器獲取接收到的 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算法的實現)
                  Sending a byte array from PHP to WCF(將字節數組從 PHP 發送到 WCF)
                • <i id='2IiIG'><tr id='2IiIG'><dt id='2IiIG'><q id='2IiIG'><span id='2IiIG'><b id='2IiIG'><form id='2IiIG'><ins id='2IiIG'></ins><ul id='2IiIG'></ul><sub id='2IiIG'></sub></form><legend id='2IiIG'></legend><bdo id='2IiIG'><pre id='2IiIG'><center id='2IiIG'></center></pre></bdo></b><th id='2IiIG'></th></span></q></dt></tr></i><div class="siwue06" id='2IiIG'><tfoot id='2IiIG'></tfoot><dl id='2IiIG'><fieldset id='2IiIG'></fieldset></dl></div>

                  • <legend id='2IiIG'><style id='2IiIG'><dir id='2IiIG'><q id='2IiIG'></q></dir></style></legend>
                        <tbody id='2IiIG'></tbody>
                      1. <small id='2IiIG'></small><noframes id='2IiIG'>

                          <bdo id='2IiIG'></bdo><ul id='2IiIG'></ul>
                        • <tfoot id='2IiIG'></tfoot>

                            主站蜘蛛池模板: 润东方环保空调,冷风机,厂房车间降温设备-20年深圳环保空调生产厂家 | 防火卷帘门价格-聊城一维工贸特级防火卷帘门厂家▲ | 焊接烟尘净化器__焊烟除尘设备_打磨工作台_喷漆废气治理设备 -催化燃烧设备 _天津路博蓝天环保科技有限公司 | 山东活动策划|济南活动公司|济南公关活动策划-济南锐嘉广告有限公司 | 雷蒙磨,雷蒙磨粉机,雷蒙磨机 - 巩义市大峪沟高峰机械厂 | YAGEO国巨电容|贴片电阻|电容价格|三星代理商-深圳市巨优电子有限公司 | 硫酸钡厂家_高光沉淀硫酸钡价格-河南钡丰化工有限公司 | 生产自动包装秤_颗粒包装秤_肥料包装秤等包装机械-郑州鑫晟重工科技有限公司 | 臭氧实验装置_实验室臭氧发生器-北京同林臭氧装置网 | 江苏密集柜_电动_手动_移动_盛隆柜业江苏档案密集柜厂家 | 油漆辅料厂家_阴阳脚线_艺术漆厂家_内外墙涂料施工_乳胶漆专用防霉腻子粉_轻质粉刷石膏-魔法涂涂 | 非甲烷总烃分析仪|环控百科 | 企业VI设计_LOGO设计公司_品牌商标设计_【北京美研】 | 低气压试验箱_高低温低气压试验箱_低气压实验箱 |林频试验设备品牌 | 土壤墒情监测站_土壤墒情监测仪_土壤墒情监测系统_管式土壤墒情站-山东风途物联网 | 板框压滤机-隔膜压滤机-厢式压滤机生产厂家-禹州市君工机械设备有限公司 | 火锅加盟_四川成都火锅店加盟_中国火锅连锁品牌十强_朝天门火锅【官网】 | 大米加工设备|大米加工机械|碾米成套设备|大米加工成套设备-河南成立粮油机械有限公司 | 书信之家_书信标准模板范文大全| 真空泵维修保养,普发,阿尔卡特,荏原,卡西亚玛,莱宝,爱德华干式螺杆真空泵维修-东莞比其尔真空机电设备有限公司 | 山东聚盛新型材料有限公司-纳米防腐隔热彩铝板和纳米防腐隔热板以及钛锡板、PVDF氟膜板供应商 | 亮点云建站-网站建设制作平台 | 一体化净水器_一体化净水设备_一体化水处理设备-江苏旭浩鑫环保科技有限公司 | 恒压供水控制柜|无负压|一体化泵站控制柜|PLC远程调试|MCGS触摸屏|自动控制方案-联致自控设备 | 河南膏药贴牌-膏药代加工-膏药oem厂家-洛阳今世康医药科技有限公司 | 药品/药物稳定性试验考察箱-埃里森仪器设备(上海)有限公司 | 电梯乘运质量测试仪_电梯安全评估测试仪-武汉懿之刻 | 心肺复苏模拟人|医学模型|急救护理模型|医学教学模型上海康人医学仪器设备有限公司 | 冲锋衣滑雪服厂家-冲锋衣定制工厂-滑雪服加工厂-广东睿牛户外(S-GERT) | 不锈钢复合板厂家_钛钢复合板批发_铜铝复合板供应-威海泓方金属复合材料股份有限公司 | 碳刷_刷握_集电环_恒压簧_电刷厂家-上海丹臻机电科技有限公司 | 一体化隔油提升设备-餐饮油水分离器-餐厨垃圾处理设备-隔油池-盐城金球环保产业发展有限公司 | 小型高低温循环试验箱-可程式高低温湿热交变试验箱-东莞市拓德环境测试设备有限公司 | 水质传感器_水质监测站_雨量监测站_水文监测站-山东水境传感科技有限公司 | 雄松华章(广州华章MBA)官网-专注MBA/MPA/MPAcc/MEM辅导培训 | PVC快速门-硬质快速门-洁净室快速门品牌厂家-苏州西朗门业 | 东莞海恒试验仪器设备有限公司| 水厂污泥地磅|污泥处理地磅厂家|地磅无人值守称重系统升级改造|地磅自动称重系统维修-河南成辉电子科技有限公司 | 铸钢件厂家-铸钢齿轮-减速机厂家-淄博凯振机械有限公司 | 结晶点测定仪-润滑脂滴点测定仪-大连煜烁| 合肥钣金加工-安徽激光切割加工-机箱机柜加工厂家-合肥通快 |