PHPMyAdmin – 資料無法匯入

Loading

測試環境 CentOS 7 64bits + Apache

我們可以透過 MyPHPAdmin 的匯入 ( Import )功能,把資料匯入資料庫,但當資料大於 2M 時會出現以下的資訊.

沒有接收到要匯入的資料。 可能是檔案名稱沒有被送出或是檔案大小超出 PHP 限制。 請參考 FAQ 1.16。
No data was received to import. Either no file name was submitted, or the file size exceeded the maximum size permitted by your PHP configuration. See FAQ 1.16.

主要是被 PHP 上傳檔案 2M 的上限所限制住,我們可以透過 PHP 函數 phpinfo() 來看一下目前關於上傳檔案限制的設定.
可以使用編輯器來鍵入 PHP 程式碼,內容如下 (檔案需儲存在 /var/www/html – Apache 預設的目錄),或是透過 echo 直接產生.

[root@benjr ~]# echo "<?php phpinfo() ?>" > /var/www/html/phpinfo.php

開啟你的網頁連上你 http://Host_IP/phpinfo.php ,如果 PHP 一切運作正常,可以找到跟上傳檔案大小相關的設定 post_max_size 與 upload_max_filesize.

  1. post_max_size – Local / Master Value 預設為 8M.
    post_max_size 是針對請求的整個主體的限制 (使用者可能一次上傳多個檔案)
  2. upload_max_filesize – Local / Master Value 預設為 2M.
    upload_max_filesize 是針對單個檔案大小的限制。

設定值有分為 Master Value (PHP.ini 設定檔) 以及 Local value (當前目錄中的設定檔,會覆蓋過 Master Value 的值),可以透過下面幾種方式來做.

  1. 修改 php.ini
    /var/www/html/php.ini
  2. 修改 .htaccess (我採用的方式)
    Apache 預設不使用 .htaccess 做設定,先確認 Apache 網頁資料夾 (預設為 /var/www/html) 權限的 AllowOverride 需設定為 All,之後在 .htaccess 設定不需重新啟動 http 服務就可立即生效.

    [root@localhost ~]# vi /etc/httpd/conf/httpd.conf
    <Directory "/var/www/html">
        AllowOverride All
    </Directory>
    
    [root@localhost ~]# systemctl restart httpd
    [root@localhost ~]# systemctl status httpd
    ● httpd.service - The Apache HTTP Server
       Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
       Active: active (running) since 二 2019-06-18 22:27:08 CST; 9s ago
         Docs: man:httpd(8)
               man:apachectl(8)
      Process: 9880 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
     Main PID: 9883 (httpd)
       Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
        Tasks: 6
       CGroup: /system.slice/httpd.service
               ├─9883 /usr/sbin/httpd -DFOREGROUND
               ├─9885 /usr/sbin/httpd -DFOREGROUND
               ├─9886 /usr/sbin/httpd -DFOREGROUND
               ├─9887 /usr/sbin/httpd -DFOREGROUND
               ├─9888 /usr/sbin/httpd -DFOREGROUND
               └─9889 /usr/sbin/httpd -DFOREGROUND
    
    [root@localhost ~]# vi /var/www/html/.htaccess
    php_value upload_max_filesize 1024M
    php_value post_max_size 1024M
    php_value max_execution_time 300
    php_value max_input_time 300
    

    當檔案比較大時所需上傳時間也需要修改,下面這兩個參數可以做調整.

    1. max_input_time integer
      This sets the maximum time in seconds a script is allowed to parse input data, like POST and GET. Timing begins at the moment PHP is invoked at the server and ends when execution begins. 預設值為 60秒.
    2. max_execution_time integer
      This sets the maximum time in seconds a script is allowed to run before it is terminated by the parser. This helps prevent poorly written scripts from tying up the server. 預設值為 30秒.

再次開啟你的網頁連上你 http://Host_IP/phpinfo.php ,檢視一下 post_max_size 與 upload_max_filesize 的 Local Value 設定都改成 1024M.

CentOS 8 64bits 使用 Apache + php-fpm 設定方式請參考 – https://benjr.tw/102232

沒有解決問題,試試搜尋本站其他內容

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料