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

  • <tfoot id='c6r05'></tfoot>
    • <bdo id='c6r05'></bdo><ul id='c6r05'></ul>
    1. <legend id='c6r05'><style id='c6r05'><dir id='c6r05'><q id='c6r05'></q></dir></style></legend>
    2. <small id='c6r05'></small><noframes id='c6r05'>

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

        上傳的文件應該重命名嗎?

        Should uploaded files be renamed?(上傳的文件應該重命名嗎?)
        • <tfoot id='h9oPG'></tfoot>

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

            <legend id='h9oPG'><style id='h9oPG'><dir id='h9oPG'><q id='h9oPG'></q></dir></style></legend>
          1. <i id='h9oPG'><tr id='h9oPG'><dt id='h9oPG'><q id='h9oPG'><span id='h9oPG'><b id='h9oPG'><form id='h9oPG'><ins id='h9oPG'></ins><ul id='h9oPG'></ul><sub id='h9oPG'></sub></form><legend id='h9oPG'></legend><bdo id='h9oPG'><pre id='h9oPG'><center id='h9oPG'></center></pre></bdo></b><th id='h9oPG'></th></span></q></dt></tr></i><div class="tf7th7p" id='h9oPG'><tfoot id='h9oPG'></tfoot><dl id='h9oPG'><fieldset id='h9oPG'></fieldset></dl></div>
              <tbody id='h9oPG'></tbody>

                <bdo id='h9oPG'></bdo><ul id='h9oPG'></ul>

                  本文介紹了上傳的文件應該重命名嗎?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我一直在閱讀有關 PHP 文件上傳安全性的文章,并且有幾篇文章建議重命名文件.例如,OWASP 文章無限制文件上傳說:

                  I've been reading up on PHP file upload security and a few articles have recommended renaming the files. For example, the OWASP article Unrestricted File Upload says:

                  建議使用算法來確定文件名.為了例如,文件名可以是文件名加上文件名的 MD5 哈希值當天的日期.

                  It is recommended to use an algorithm to determine the filenames. For instance, a filename can be a MD5 hash of the name of file plus the date of the day.

                  如果用戶上傳了一個名為 Cake Recipe.doc 的文件,是否真的有理由將其重命名為 45706365b7d5b1f35?

                  If a user uploads a file named Cake Recipe.doc is there really any reason to rename it to 45706365b7d5b1f35?

                  如果答案是肯定的,無論出于何種原因,那么您如何跟蹤原始文件名和擴展名?

                  If the answer is yes, for whatever reason, then how do you keep track of the original file name and extension?

                  推薦答案

                  對于您的主要問題,重命名文件是否是一種好習慣,答案是肯定的,特別是如果您正在創建一種用戶上傳的文件存儲庫形式他們選擇的文件(和文件名),原因如下:

                  To your primary question, is it good practice to rename files, the answer is a definite yes, especially if you are creating a form of File Repository where users upload files (and filenames) of their choosing, for several reason:

                  1. 安全性 - 如果您的應用程序編寫不當,允許按名稱或通過直接訪問下載文件(這很可怕,但確實發生了),那么用戶(無論是惡意的還是故意的)就更難猜測"" 文件名.
                  2. 唯一性 -- 兩個不同的人上傳同名文件的可能性非常高(即 avatar.gif、readme.txt、video.avi 等).使用唯一標識符可顯著降低兩個文件同名的可能性.
                  3. 版本控制——使用唯一名稱保存文檔的多個版本"要容易得多.它還避免了需要額外的代碼來解析文件名以進行更改.一個簡單的例子是將 document.pdf 轉換為 document(1).pdf,當您不低估用戶為事物創建可怕名稱的能力時,這會變得更加復雜.
                  4. Length -- 使用已知的文件名長度總是比使用未知的文件名長度更好.我總是可以知道(我的文件路徑)+(X 個字母)是某個長度,其中(我的文件路徑)+(隨機用戶文件名)是完全未知的.
                  5. OS -- 在嘗試將極其隨機/長的文件名寫入驅動器時,上述長度也會產生問題.您必須考慮特殊字符、長度和修剪文件名的問題(用戶可能無法收到工作文件,因為擴展名已被修剪).
                  6. 執行 -- 操作系統很容易執行名為 .exe、.php 或(插入其他擴展名)的文件.沒有擴展就很難.
                  7. URL 編碼 -- 確保名稱是 URL 安全的.Cake Recipe.doc 不是 URL 安全名稱,并且可能在某些系統(服務器端或瀏覽器端)/某些情況下,當名稱應為 urlencode 時導致不一致d 值.
                  1. Security - if you have a poorly written application that allows the download of files by name or through direct access (it's a horrid, but it happens), it's much harder for a user, whether maliciously or on purpose, to "guess" the names of files.
                  2. Uniqueness -- the likelihood of two different people uploading a file of the same name is very high (ie. avatar.gif, readme.txt, video.avi, etc). The use of a unique identifier significantly decreases the likelihood that two files will be of the same name.
                  3. Versioning -- It is much easier to keep multiple "versions" of a document using unique names. It also avoids the need for additional code to parse a filename to make changes. A simple example would document.pdf to document(1).pdf, which becomes more complicated when you don't underestimate users abilities to create horrible names for things.
                  4. Length -- working with known filename lengths is always better than working with unknown filename lengths. I can always know that (my filepath) + (X letters) is a certain length, where (my filepath) + (random user filename) is completely unknown.
                  5. OS -- the length above can also create problems when attempting to write extremely random/long filenames to a drive. You have to account for special characters, lengths and the concerns for trimmed filenames (user may not receive a working file because the extension has been trimmed).
                  6. Execution -- It's easy for the OS to execute a file named .exe, or .php, or (insert other extension). It's hard when there isn't an extension.
                  7. URL encoding -- Ensuring the name is URL safe. Cake Recipe.doc is not a URL safe name, and can on some systems (either server or browser side) / some situations, cause inconsistencies when the name should be a urlencoded value.

                  至于存儲信息,您通常會在數據庫中執行此操作,這與您已有的需求沒有什么不同,因為您需要一種方法來引用文件(誰上傳,名稱是什么,有時它在哪里存儲,上傳時間,有時是大小).除了文件的用戶名之外,您只需添加文件的實際存儲名稱.

                  As for storing the information, you would typically do this in a database, no different than the need you have already, since you need a way to refer back to the file (who uploaded, what the name is, occassionally where it is stored, the time of upload, sometimes the size). You're simply adding to that the actual stored name of the file in addition to the user's name for the file.

                  OWASP 的建議不錯——使用文件名和時間戳(不是日期)大多是唯一的.我更進一步,包括帶有時間戳的微時間,以及其他一些獨特的信息,這樣就不會在同一時間段內重復上傳小文件——我還存儲了上傳日期這是針對 md5 沖突的額外保險,在存儲許多文件和多年的系統中,這種沖突的可能性更高.您極不可能在同一天使用文件名和微時間生成兩個像 md5s 一樣的文件.一個例子是:

                  The OWASP recommendation isn't a bad one -- using the filename and a timestamp (not date) would be mostly unique. I take it a step further to include the microtime with the timestamp, and often some other unique bit of information, so that a duplicate upload of a small file couldn't occur in the same timeframe -- I also store the date of the upload which is additional insurance against md5 clashes, which has a higher probability in systems that store many files and for years. It is incredibly unlikely that you would generate two like md5s, using filename and microtime, on the same day. An example would be:

                  $filename = date('Ymd') . '_' . md5($uploaded_filename . microtime());
                  

                  我的 2 美分.

                  這篇關于上傳的文件應該重命名嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)

                        <bdo id='dUwC3'></bdo><ul id='dUwC3'></ul>

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

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

                            主站蜘蛛池模板: 红外光谱仪维修_二手红外光谱仪_红外压片机_红外附件-天津博精仪器 | Trimos测长机_测高仪_TESA_mahr,WYLER水平仪,PWB对刀仪-德瑞华测量技术(苏州)有限公司 | 翰墨AI智能写作助手官网_人工智能问答在线AI写作免费一键生成 | 步进_伺服_行星减速机,微型直流电机,大功率直流电机-淄博冠意传动机械 | 过滤器_自清洗过滤器_气体过滤器_苏州华凯过滤技术有限公司 | 异噻唑啉酮-均三嗪-三丹油-1227-中北杀菌剂厂家 | 涡轮流量计_LWGY智能气体液体电池供电计量表-金湖凯铭仪表有限公司 | ph计,实验室ph计,台式ph计,实验室酸度计,台式酸度计 | 联系我们老街华纳娱乐公司官网19989979996(客服) | jrs高清nba(无插件)直播-jrs直播低调看直播-jrs直播nba-jrs直播 上海地磅秤|电子地上衡|防爆地磅_上海地磅秤厂家–越衡称重 | 天然气分析仪-液化气二甲醚分析仪|传昊仪器 | 上海办公室装修,办公楼装修设计,办公空间设计,企业展厅设计_写艺装饰公司 | 防爆电机_防爆电机型号_河南省南洋防爆电机有限公司 | 无锡市珂妮日用化妆品有限公司|珂妮日化官网|洗手液厂家 | 三防漆–水性三防漆–水性浸渍漆–贝塔三防漆厂家 | 懂研帝_专业SCI论文润色机构_SCI投稿发表服务公司 | 家德利门业,家居安全门,别墅大门 - 安徽家德利门业有限公司 | 杭州代理记账多少钱-注册公司代办-公司注销流程及费用-杭州福道财务管理咨询有限公司 | 证券新闻,热播美式保罗1984第二部_腾讯1080p-仁爱影院 | 扬尘监测_扬尘监测系统_带证扬尘监测设备 - 郑州港迪科技有限公司 | 三轴曲线机-端子插拔力试验机|华杰仪器 | 万濠影像仪(万濠投影仪)百科-苏州林泽仪器 | 搬运设备、起重设备、吊装设备—『龙海起重成套设备』 | 耙式干燥机_真空耙式干燥机厂家-无锡鹏茂化工装备有限公司 | 珠海白蚁防治_珠海灭鼠_珠海杀虫灭鼠_珠海灭蟑螂_珠海酒店消杀_珠海工厂杀虫灭鼠_立净虫控防治服务有限公司 | 北京浩云律师事务所-企业法律顾问_破产清算等公司法律服务 | 脱硫搅拌器厂家-淄博友胜不锈钢搅拌器厂家 | 石英粉,滑石粉厂家,山东滑石粉-莱州市向阳滑石粉有限公司 | 红立方品牌应急包/急救包加盟,小成本好项目代理_应急/消防/户外用品加盟_应急好项目加盟_新奇特项目招商 - 中红方宁(北京) 供应链有限公司 | 杭州公司变更法人-代理记账收费价格-公司注销代办_杭州福道财务管理咨询有限公司 | 幂简集成 - 品种超全的API接口平台, 一站搜索、试用、集成国内外API接口 | 手板_手板模型制作_cnc手板加工厂-东莞天泓 | 全国国际化学校_国际高中招生_一站式升学择校服务-国际学校网 | 专业甜品培训学校_广东糖水培训_奶茶培训_特色小吃培训_广州烘趣甜品培训机构 | 合肥白癜风医院_合肥治疗白癜风医院_合肥看白癜风医院哪家好_合肥华研白癜风医院 | 【化妆品备案】进口化妆品备案流程-深圳美尚美化妆品有限公司 | 基本型顶空进样器-全自动热脱附解吸仪价格-AutoHS全模式-成都科林分析技术有限公司 | UV固化机_UVLED光固化机_UV干燥机生产厂家-上海冠顶公司专业生产UV固化机设备 | 开云(中国)Kaiyun·官方网站-登录入口 | 金属切削液-脱水防锈油-电火花机油-抗磨液压油-深圳市雨辰宏业科技发展有限公司 | 知名电动蝶阀,电动球阀,气动蝶阀,气动球阀生产厂家|价格透明-【固菲阀门官网】 |