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

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

      <small id='7MyGY'></small><noframes id='7MyGY'>

    1. <legend id='7MyGY'><style id='7MyGY'><dir id='7MyGY'><q id='7MyGY'></q></dir></style></legend><tfoot id='7MyGY'></tfoot>

      使用 PHP 創建單文件上傳表單的最佳方法是什么

      What#39;s the best way to create a single-file upload form using PHP?(使用 PHP 創建單文件上傳表單的最佳方法是什么?)

      1. <small id='dMU1w'></small><noframes id='dMU1w'>

      2. <legend id='dMU1w'><style id='dMU1w'><dir id='dMU1w'><q id='dMU1w'></q></dir></style></legend>

            <tbody id='dMU1w'></tbody>
          <tfoot id='dMU1w'></tfoot>

              • <bdo id='dMU1w'></bdo><ul id='dMU1w'></ul>
                <i id='dMU1w'><tr id='dMU1w'><dt id='dMU1w'><q id='dMU1w'><span id='dMU1w'><b id='dMU1w'><form id='dMU1w'><ins id='dMU1w'></ins><ul id='dMU1w'></ul><sub id='dMU1w'></sub></form><legend id='dMU1w'></legend><bdo id='dMU1w'><pre id='dMU1w'><center id='dMU1w'></center></pre></bdo></b><th id='dMU1w'></th></span></q></dt></tr></i><div class="xxv7l5t" id='dMU1w'><tfoot id='dMU1w'></tfoot><dl id='dMU1w'><fieldset id='dMU1w'></fieldset></dl></div>
                本文介紹了使用 PHP 創建單文件上傳表單的最佳方法是什么?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                限時送ChatGPT賬號..

                我在網上找到了一些示例,但我想從每天使用 PHP 的人那里獲得關于潛在安全或性能考慮因素及其解決方案的反饋.

                I've found a few samples online but I'd like to get feedback from people who use PHP daily as to potential security or performance considerations and their solutions.

                請注意,我只對一次上傳一個文件感興趣.

                Note that I am only interested in uploading a single file at a time.

                理想情況下不需要瀏覽器插件(Flash/Java),盡管了解使用插件的好處會很有趣.

                Ideally no browser plugin would be required (Flash/Java), although it would be interesting to know the benefits of using a plugin.

                我想知道最好的 HTML 表單代碼和 PHP 處理代碼.

                I would like to know both the best HTML form code and PHP processing code.

                推薦答案

                文件上傳教程

                HTML

                <form enctype="multipart/form-data" action="action.php" method="POST">
                  <input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
                  <input name="userfile" type="file" />
                  <input type="submit" value="Go" />
                </form>
                

                • action.php 是將處理上傳的 PHP 文件的名稱(如下所示)
                • MAX_FILE_SIZE 必須出現在類型為 file 的輸入之前.這個值可以很容易地在客戶端上操作,所以不應該依賴.它的主要好處是在用戶上傳文件之前向用戶提供文件過大的早期警告.
                • 您可以使用 file 類型更改輸入的名稱,但請確保它不包含任何空格.您還必須更新 PHP 文件中的相應值(如下).
                  • action.php is the name of a PHP file that will process the upload (shown below)
                  • MAX_FILE_SIZE must appear immediately before the input with type file. This value can easily be manipulated on the client so should not be relied upon. Its main benefit is to provide the user with early warning that their file is too large, before they've uploaded it.
                  • You can change the name of the input with type file, but make sure it doesn't contain any spaces. You must also update the corresponding value in the PHP file (below).
                  • <?php
                    $uploaddir = "/www/uploads/";
                    $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
                    
                    echo '<pre>';
                    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
                        echo "Success.
                    ";
                    } else {
                        echo "Failure.
                    ";
                    }
                    
                    echo 'Here is some more debugging info:';
                    print_r($_FILES);
                    print "</pre>";
                    ?>
                    
                    The upload-to folder should not be located in a place that's accessible via HTTP, otherwise it would be possible to upload a PHP script and execute it upon the server.

                    upload-to 文件夾不應位于可通過 HTTP 訪問的位置,否則可能上傳 PHP 腳本并在服務器上執行.

                    Printing the value of $_FILES can give a hint as to what's going on. For example:

                    打印$_FILES 的值可以提示發生了什么.例如:

                    Array ( [userfile] => Array ( [name] => Filename.ext [type] => [tmp_name] => [error] => 2 [size] => 0 ) )

                    這個結構提供了一些關于文件名、MIME 類型、大小和錯誤代碼的信息.

                    This structure gives some information as to the file's name, MIME type, size and error code.

                    0 表示沒有錯誤,文件上傳成功
                    1 表示文件超過了 php.ini 中定義的最大文件大小.如果您想更改最大文件大小,您需要打開您的 php.ini 文件,確定讀取的行:upload_max_filesize = 2M 并將值從 2M (2MB) 更改為您需要的任何值
                    2 表示已超出頁面腳本中手動定義的最大文件大小
                    3 表示文件只上傳了部分
                    4 表示沒有指定文件(空文件字段)
                    5 尚未定義
                    6 表示沒有臨時文件夾
                    7 表示文件無法寫入磁盤

                    0 Indicates that there was no errors and file has been uploaded successfully
                    1 Indicates that the file exceeds the maximum file size defined in php.ini. If you would like to change the maximum file size, you need to open your php.ini file, identify the line which reads: upload_max_filesize = 2M and change the value from 2M (2MB) to whatever you need
                    2 Indicates that the maximum file size defined manually, within an on page script has been exceeded
                    3 Indicates that file has only been uploaded partially
                    4 Indicates that the file hasn't been specified (empty file field)
                    5 Not defined yet
                    6 Indicates that there′s no temporary folder
                    7 Indicates that the file cannot be written to the disk

                    php.ini 配置

                    使用較大的文件運行此設置時,您可能會收到錯誤消息.檢查您的 php.ini 文件中的這些鍵:

                    php.ini Configuration

                    When running this setup with larger files you may receive errors. Check your php.ini file for these keys:

                    max_execution_time = 30
                    upload_max_filesize = 2M

                    適當增加這些值可能會有所幫助.使用 Apache 時,對此文件的更改需要重新啟動.

                    Increasing these values as appropriate may help. When using Apache, changes to this file require a restart.

                    最大內存允許值(通過 memory_limit 設置)在此處不起作用,因為文件在上傳時寫入 tmp 目錄.tmp 目錄的位置可以通過 upload_tmp_dir 控制.

                    The maximum memory permitted value (set via memory_limit) does not play a role here as the file is written to the tmp directory as it is uploaded. The location of the tmp directory is optionally controlled via upload_tmp_dir.

                    您應該檢查用戶上傳的文件類型 - 最佳做法是根據允許的文件類型列表進行驗證.允許任何文件的潛在風險是用戶可能將 PHP 代碼上傳到服務器然后運行它.

                    You should check the filetype of what the user is uploading - the best practice is to validate against a list of allowed filetypes. A potential risk of allowing any file is that a user could potentially upload PHP code to the server and then run it.

                    您可以使用非常有用的fileinfo 擴展(取代舊的 mime_content_type 函數)來驗證 MIME 類型.

                    You can use the very useful fileinfo extension (that supersedes the older mime_content_type function) to validate mime-types.

                    // FILEINFO_MIME set to return MIME types, will return string of info otherwise
                    $fileinfo = new finfo(FILEINFO_MIME);
                    $file = $fileinfo->file($_FILE['filename']);
                    
                    $allowed_types = array('image/jpeg', 'image/png');
                    if(!in_array($file, $allowed_types))
                    {
                        die('Files of type' . $file . ' are not allowed to be uploaded.');
                    }
                    // Continue
                    

                    更多信息

                    您可以在 PHP.net 手冊中閱讀有關處理文件上傳的更多信息.

                    //For those who are using PHP 5.3, the code varies.
                    $fileinfo = new finfo(FILEINFO_MIME_TYPE);
                    $file = $fileinfo->file($_FILE['filename']['tmp_name']);
                    $allowed_types = array('image/jpeg', 'image/png');
                    if(!in_array($file, $allowed_types))
                    {
                        die('Files of type' . $file . ' are not allowed to be uploaded.');
                    }
                    // Continue
                    

                    更多信息

                    您可以在 PHP.net 文檔中閱讀有關 FILEINFO_MIME_TYPE 的更多信息.

                    More Information

                    You can read more on FILEINFO_MIME_TYPE at the PHP.net documentation.

                    這篇關于使用 PHP 創建單文件上傳表單的最佳方法是什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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)

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

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

                        1. <legend id='Xt8ld'><style id='Xt8ld'><dir id='Xt8ld'><q id='Xt8ld'></q></dir></style></legend>

                          主站蜘蛛池模板: 蓄电池在线监测系统|SF6在线监控泄露报警系统-武汉中电通电力设备有限公司 | 土壤水分自动监测站-SM150便携式土壤水分仪-铭奥仪器 | 济南宣传册设计-画册设计_济南莫都品牌设计公司 | 龙门加工中心-数控龙门加工中心厂家价格-山东海特数控机床有限公司_龙门加工中心-数控龙门加工中心厂家价格-山东海特数控机床有限公司 | 南京展台搭建-南京展会设计-南京展览设计公司-南京展厅展示设计-南京汇雅展览工程有限公司 | 双段式高压鼓风机-雕刻机用真空泵-绍兴天晨机械有限公司 | 厂房出售_厂房仓库出租_写字楼招租_土地出售-中苣招商网-中苣招商网 | 防爆电机_防爆电机型号_河南省南洋防爆电机有限公司 | 阿尔法-MDR2000无转子硫化仪-STM566 SATRA拉力试验机-青岛阿尔法仪器有限公司 | 河南正规膏药生产厂家-膏药贴牌-膏药代加工-修康药业集团官网 | Maneurop/美优乐压缩机,活塞压缩机,型号规格,技术参数,尺寸图片,价格经销商 | 工业风机_环保空调_冷风机_工厂车间厂房通风降温设备旺成服务平台 | 插针变压器-家用电器变压器-工业空调变压器-CD型电抗器-余姚市中驰电器有限公司 | 石英砂矿石色选机_履带辣椒色选机_X光异物检测机-合肥幼狮光电科技 | 数显水浴恒温振荡器-分液漏斗萃取振荡器-常州市凯航仪器有限公司 | 真空上料机(一种真空输送机)-百科 | 层流手术室净化装修-检验科ICU改造施工-华锐净化工程-特殊科室建设厂家 | 温州富欧金属封头-不锈钢封头厂家| 踏板力计,制动仪,非接触多功能速度仪,逆反射系数测试仪-创宇 | 密度电子天平-内校-外校电子天平-沈阳龙腾电子有限公司 | 智能楼宇-楼宇自控系统-楼宇智能化-楼宇自动化-三水智能化 | 北京签证代办_签证办理_商务签证_旅游签证_寰球签证网 | 传爱自考网_传爱自学考试网 | 【365公司转让网】公司求购|转让|资质买卖_股权转让交易平台 | 北京银联移动POS机办理_收银POS机_智能pos机_刷卡机_收银系统_个人POS机-谷骐科技【官网】 | 柴油发电机组_柴油发电机_发电机组价格-江苏凯晨电力设备有限公司 | 体检车_移动CT车_CT检查车_CT车_深圳市艾克瑞电气有限公司移动CT体检车厂家-深圳市艾克瑞电气有限公司 | 学校用栓剂模,玻璃瓶轧盖钳,小型安瓿熔封机,实验室安瓿熔封机-长沙中亚制药设备有限公司 | 安驭邦官网-双向万能直角铣头,加工中心侧铣头,角度头[厂家直销] 闸阀_截止阀_止回阀「生产厂家」-上海卡比阀门有限公司 | 深圳希玛林顺潮眼科医院(官网)│深圳眼科医院│医保定点│香港希玛林顺潮眼科中心连锁品牌 | 自动检重秤-动态称重机-重量分选秤-苏州金钻称重设备系统开发有限公司 | AGV无人叉车_激光叉车AGV_仓储AGV小车_AGV无人搬运车-南昌IKV机器人有限公司[官网] | 东莞螺丝|东莞螺丝厂|东莞不锈钢螺丝|东莞组合螺丝|东莞精密螺丝厂家-东莞利浩五金专业紧固件厂家 | 卫生纸复卷机|抽纸机|卫生纸加工设备|做卫生纸机器|小型卫生纸加工需要什么设备|卫生纸机器设备多少钱一台|许昌恒源纸品机械有限公司 | 水压力传感器_数字压力传感器|佛山一众传感仪器有限公司|首页 | 河北凯普威医疗器材有限公司,高档轮椅系列,推车系列,座厕椅系列,协步椅系列,拐扙系列,卫浴系列 | 废水处理-废气处理-工业废水处理-工业废气处理工程-深圳丰绿环保废气处理公司 | SOUNDWELL 编码器|电位器|旋转编码器|可调电位器|编码开关厂家-广东升威电子制品有限公司 | 丹尼克尔拧紧枪_自动送钉机_智能电批_柔性振动盘_螺丝供料器品牌 | 钢丝绳探伤仪-钢丝绳检测仪-钢丝绳探伤设备-洛阳泰斯特探伤技术有限公司 | 行星齿轮减速机,减速机厂家,山东减速机-淄博兴江机械制造 |