Tags:
By Unknown → Thursday, January 15, 2015
Kita mungkin pernah mengalami error "POST Content-Length Exceeds The Limit" saat membuat aplikasi upload file via HTTP Post menggunakan script PHP.
PHP Warning: POST Content-Length of 11933650 bytes exceeds the limit of 8388608 bytes in Unknown on line 0

Hal ini terjadi karena konfigurasi php di server hanya membolehkan upload file melalui HTTP Post sebesar 8MB (8388608 bytes). Oleh karena itu, untuk mengatasi hal ini, konfigurasi php di server harus diganti. Caranya sebagai berikut :
  1. Buka file php.ini
  2. Ganti nilai parameter upload_max_filesize dan post_max_size
    Sebelum diubah :
    upload_max_filesize = 2M
    post_max_size = 8M

    Setelah diubah :
    upload_max_filesize = 1024M
    post_max_size = 1054M
    Nilai 1024M berarti kita membolehkan upload file melalui HTTP Post sebesar maksimal 1GB (1024MB). Silahkan diganti sesuai dengan kebutuhan. Sebagai catatan, nilai post_max_size harus lebih besar dari upload_max_filesize karena saat melakukan upload file melalui HTTP Post, data yang di-upload juga mengandung nilai header (ukuran file, nama file, dll), sehingga ukuran post_max_size harus lebih besar dari nilai upload_max_file_size.
  3. Jika dibutuhkan (optional), ganti juga nilai parameter max_execution_time (nilai dalam bentuk detik).
    Sebelum diubah :
    max_execution_time=30

    Setelah diubah :
    max_execution_time=600000

Jika Anda tidak memiliki akses ke server (tidak dapat mengakses file php.ini), Anda dapat melakukan perubahan konfigurasi php melalui file .htaccess Caranya sebagai berikut :
  1. Untuk menggunakan file .htaccess, pastikan web server tempat Anda meletakkan script PHP, nilai AllowOverride sudah: AllowOverride All. Untuk mengganti nilai AllowOverride, buka file httpd.conf, lalu edit di baris AllowOverride dengan nilai seperti di bawah ini :
    #
    # This should be changed to whatever you set DocumentRoot to.
    #
    <Directory "/var/www/html/htdocs">
    #
    # Possible values for the Options directive are "None", "All",
    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    # Options FileInfo AuthConfig Limit
    #
    AllowOverride All
    #
    # Controls who can get stuff from this server.
    #
    Require all granted
    </Directory>
  2. Buat file dengan nama file .htaccess
  3. Lalu isi file .htaccess dengan script di bawah ini :
    php_value memory_limit 30M
    php_value upload_max_filesize 1024M
    php_value post_max_size 1054M
    Jika web server Anda menggunakan php5, maka Anda harus menggunakan php5_value, seperti contoh di bawah ini :
    php5_value memory_limit 30M
    php5_value upload_max_filesize 1024M
    php5_value post_max_size 1054M
  4. Simpan file .htaccess di root directory server Anda.

Post Tags:

Martin Tobing

I'm Martin Tobing. A full time web programmer. I enjoy to make website and web application in PHP.

No Comment to " POST Content-Length Exceeds The Limit "