GVKun编程网logo

PHP警告:POST Content-Length的8978294字节超出了第0行中Unknown中的8388608字节的限制

11

如果您对PHP警告:POSTContent-Length的8978294字节超出了第0行中Unknown中的8388608字节的限制感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解PHP警告:P

如果您对PHP警告:POST Content-Length的8978294字节超出了第0行中Unknown中的8388608字节的限制感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解PHP警告:POST Content-Length的8978294字节超出了第0行中Unknown中的8388608字节的限制的各种细节,此外还有关于android – 计算Base64编码文件的Post Content-Length的大小、CentOS ping: unknown host 解决方法、centOS 之 java.net.UnknownHostException: centos: centos: 未知的名称或服务、CentOS 挂载NTFS格式的U盘报 unknown filesystem type ‘ntfs’的实用技巧。

本文目录一览:

PHP警告:POST Content-Length的8978294字节超出了第0行中Unknown中的8388608字节的限制

PHP警告:POST Content-Length的8978294字节超出了第0行中Unknown中的8388608字节的限制

尝试在XAMPP本地开发环境上的WordPress上上传导入时出现此错误:

警告:POST Content-Length的8978294字节超出了第0行中Unknown中的8388608字节的限制

upload_max_filesize从更改2M1000M,但似乎没有任何作用。

有任何想法吗?

答案1

小编典典

8388608字节为8M,这是PHP中的默认限制。将您post_max_size的php.ini 更新为更大的值。

upload_max_filesize设置用户可以上传的最大文件大小,同时 post_max_size设置可以通过POST形式发送的最大数据量。

因此,您可以将其设置upload_max_filesize为1兆,这意味着用户可以上传的最大单个文件为1
MB,但是如果将post_max_size其设置为5 ,则他们可以一次上传5 个文件。

android – 计算Base64编码文件的Post Content-Length的大小

android – 计算Base64编码文件的Post Content-Length的大小

我正在尝试将一些大型文件从 Android设备上传到.Net Web服务.此Web服务已设置为接受这些文件作为POST参数,并且文件必须作为Base64编码的字符串发送.

我已经能够使用Christian d’Heure的this库将文件转换为Base64字符串,以字节为单位计算字符串的大小并将其先前发送,但我之前使用的方法包括将整个文件加载到内存中.处理大文件时导致内存不足错误,这并不意外.

我一直在尝试将文件转换为块中的Base64并在转换时通过连接(使用数据输出流对象)传输此数据,因此整个文件不需要一次性加载到内存中,在转换文件之前,我似乎无法准确计算出请求的Content-Length的大小 – 我通常看起来大概是10个字节 – 令人沮丧的是,它偶尔会起作用!

我还发现,有些时候,这确实有效,服务器返回以下错误消息“Base64 char数组的大小无效”.我认为这是一个填充字符的问题,但是我看不出我的代码有问题,这个问题的一些建议将非常感谢!

这是生成请求并流式传输数据的代码:

try
{


    HttpURLConnection connection = null;

    DataOutputStream outputStream = null;

    DataInputStream inputStream = null;

    //This is the path to the file
    String pathToOurFile = Environment
            .getExternalStorageDirectory().getPath()
            + "/path/to/the/file.zip";

    String urlServer = "https://www.someserver.com/somewebservice/";

    int bytesRead,bytesAvailable,bufferSize;

    byte[] buffer;

    int maxBufferSize = 456;


    //The parameters of the POST request - File Data is the file in question as a Base64 String
    String params = "Username=foo&Password=bar&FileData=";

    File sizeCheck = new File(pathToOurFile);

    Integer zipSize = (int) sizeCheck.length();

    Integer paddingrequired = ((zipSize * 8) / 6) % 3;

    Integer base64ZipSize = ((zipSize * 8) / 6)
            + ((zipSize * 8) / 6) % 3;

    Integer paramLength = params.getBytes().length;

    //Code to work out the number of lines required,assuming we create a new
    //line every 76 characters - this is used t work out the number of
    //extra bytes required for new line characters
    Integer numberOfLines = base64ZipSize / 76;

    Log.i(TAG,"numberOfLines: " + numberOfLines);

    Integer newLineLength = System.getProperty("line.separator")
            .getBytes().length;

    //This works out the total length of the Content
    Integer totalLength = paramLength + base64ZipSize
            + (numberOfLines * newLineLength) + paddingrequired;

    Log.i(TAG,"total Length: " + totalLength);

    FileInputStream fileInputStream = new FileInputStream(new File(
            pathToOurFile));

    URL url = new URL(urlServer);

    connection = (HttpURLConnection) url.openConnection();

    connection.setDoInput(true);

    connection.setDoOutput(true);

    connection.setUseCaches(false);

    connection.setRequestMethod("POST");

    connection.setRequestProperty("Connection","Keep-Alive");

    connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded;");

    connection.setRequestProperty("Content-Length",""
            + totalLength); // number of bytes

    outputStream = new DataOutputStream(
            connection.getoutputStream());

    //Write out the parameters to the data output stream
    outputStream.writeBytes(params);

    bytesAvailable = fileInputStream.available();

    bufferSize = Math.min(bytesAvailable,maxBufferSize);

    buffer = new byte[bufferSize];

    bytesRead = fileInputStream.read(buffer,bufferSize);

    Integer totalSent = paramLength;

    Integer enLen = 0;


    //Convert the file to Base64 and Stream the result to the
    //Data output stream
    while (bytesRead > 0)
    {
        String convetedBase64 = Base64Coder.encodeLines(buffer);
        convetedBase64 = convetedBase64.replace("=","");

        if (totalSent >= (totalLength - 616))
        {
            Log.i(TAG,"about to send last chunk of data");
            convetedBase64 = convetedBase64.substring(0,convetedBase64.length() - 1);
        }

        Log.i(TAG,"next data chunk to send: "
                        + convetedBase64.getBytes().length);
        Log.i(TAG,"''" + convetedBase64 + "''");

        enLen = enLen + convetedBase64.length();
        outputStream.writeBytes(convetedBase64);

        totalSent = totalSent + convetedBase64.getBytes().length;

        Log.i(TAG,"total sent " + totalSent);
        Log.i(TAG,"actual size: " + outputStream.size());

        bytesAvailable = fileInputStream.available();
        bufferSize = Math.min(bytesAvailable,maxBufferSize);
        buffer = new byte[bufferSize];
        bytesRead = fileInputStream.read(buffer,bufferSize); // read
                                                                    // into
                                                                    // the
                                                                    // buffer
    }

    Log.i(TAG,"enLen: " + enLen);
    Log.i(TAG,"paddingrequired: " + paddingrequired);

    for (int x = 0; x < paddingrequired; x++)
    {
        outputStream.writeBytes("=");
    }

    InputStream is2 = connection.getInputStream();
    String output = IoUtils.toString(is2);
    Log.i(TAG,"Got server response: " + output);
    fileInputStream.close();
    outputStream.flush();
    outputStream.close();
}
catch (Exception ex)
{
    Log.e(TAG,"caught an exception:" + ex.getMessage());
}

如果有人能指出我的代码中可能导致此错误的任何错误,或者建议更好的转换和上传文件的方式,我将非常感激.

解决方法

Soooo ……我确实设法找到了一些解决这个问题的方法,以防万一有人在这个问题上绊倒我会留在这里:

第一个是将数据写入一个临时文件,所以我可以在转换后以字节为单位获得大小 – 一开始似乎是一个好主意,但效率低下并且在发现其他方法之后似乎很愚蠢.

另一种方法是不指定内容长度(我不知道你可以这样做!).不幸的是,Android仍然试图为上传分配足够的内存,这导致了问题.

如果你指定连接使用ChunkedStreamingMode Android然后播放不错并缓冲上传,节省使用的ram(除了2.2上的一个奇怪的bug).

这样的代码是这样的:

httppost.setDoInput(true);
httppost.setDoOutput(true);
httppost.setRequestMethod("POST");
httppost.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
httppost.setChunkedStreamingMode(0); //This specifies the size of the chunks - 0 uses the system default

DataOutputStream dos = new DataOutputStream(httppost.getoutputStream());
dos.writeBytes(content); //This code write out the rest of the post body first,for example username or password

try
{
    BufferedInputStream dis = new BufferedInputStream(new FileInputStream("path/to/some/file"),2048);

    byte[] in = new byte[512];

    while (dis.read(in)) > 0)
    {
        dos.write(Base64.encode(in,Base64.URL_SAFE)); //This writes out the Base64 data
                                                       //I used the web safe base64 to save URL encoding it again
                                                       //However your server must support this
        dos.write(newLine); //this write out a newline character
    }

dos.flush();
dis.close();
dos.close();

我希望这有帮助!!!

CentOS ping: unknown host 解决方法

CentOS ping: unknown host 解决方法

如果某台Linux(CentOS)服务器ping域名, 如下提示:
# ping www.sina.com
ping: unknown host www.sina.com

确认网络没问题的情况下, 可以通过如下步骤寻找解决办法:
1) 确认设置了域名服务器

 
  # cat /etc/resolv.conf
   nameserver 8.8.8.8   #(Google的公共DNS服务)
   nameserver 8.8.4.4   #(Google的公共DNS服务)

2) 确认网关已设置/确认路由表正常

   # netstat -rn
   Kernel IP routing table
   Destination Gateway Genmask Flags MSS Window irtt Iface
   0.0.0.0 10.10.10.1 0.0.0.0 UG 0 0 0 eth0

  如果未设置, 则通过如下方式增加网关:
  # route add default gw 10.245.75.1

  # grep GATEWAY /etc/sysconfig/network-scripts/ifcfg*
  /etc/sysconfig/network-scripts/ifcfg-eth0:GATEWAY=10.245.75.1

3) 确认可用dns解析

  # grep hosts /etc/nsswitch.conf
  hosts:     files dns


以上的1) 2) 3) 点只是确认问题,个人喜欢手工编写配置文件,一次解决问题。
  配置/etc/sysconfig/network-scripts/ifcfg-eth0文件后,重启network服务:
  vim /etc/sysconfig/network-scripts/ifcfg-eth0
  DEVICE="eth0"
  NM_CONTROLLED="yes"
  ONBOOT=yes
  TYPE=Ethernet
  BOOTPROTO=static
  IPADDR=10.245.75.240
  #PREFIX=24
  GATEWAY=10.245.75.1
  DNS1=8.8.8.8
  DNS2=8.8.4.4
  DEFROUTE=yes
  IPV4_FAILURE_FATAL=yes
  IPV6INIT=yes
  NAME="System eth0"
  UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx # uuid
  HWADDR=xx:xx:xx:xx:xx:xx                 # hwaddr
  NETWORKING=yes

  # service network restart

centOS 之 java.net.UnknownHostException: centos: centos: 未知的名称或服务

centOS 之 java.net.UnknownHostException: centos: centos: 未知的名称或服务

  • 应用场景:启动 javaWeb 项目时,报错后终止。提示如下:

    Initializing EhCache CacheManager 2019-10-21 22:36:20.486 ERROR 9783 --- [main] net.sf.ehcache.Cache : Unable to set localhost. This prevents creation of a GUID. Cause was: centos: centos: 未知的名称或服务

      java.net.UnknownHostException: centos: centos: 未知的名称或服务
       at java.net.InetAddress.getLocalHost(InetAddress.java:1506) ~[na:1.8.0_231]
       at net.sf.ehcache.Cache.<clinit>(Cache.java:214) ~[ehcache-core-2.6.11.jar!/:na]
       at net.sf.ehcache.config.ConfigurationHelper.createCache(ConfigurationHelper.java:296) [ehcache-core-2.6.11.jar!/:na]
       at net.sf.ehcache.config.ConfigurationHelper.createDefaultCache(ConfigurationHelper.java:219) [ehcache-core-2.6.11.jar!/:na]
       at net.sf.ehcache.CacheManager.configure(CacheManager.java:722) [ehcache-core-2.6.11.jar!/:na]
    
  • 产生原因: 当前用户未同 127.0.0.1 建立映射关系

  • 解决办法: 编辑 hosts 文件,将报错名称添加到 127.0.0.1 的映射中

      127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4  centos //此处添加centos
      ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    

CentOS 挂载NTFS格式的U盘报 unknown filesystem type ‘ntfs’

CentOS 挂载NTFS格式的U盘报 unknown filesystem type ‘ntfs’

mount: unknown filesystem type ‘ntfs’

  这是由于CentOS 上无法识别NTFS格式的分区。 

解决办法: 
      通过使用 ntfs-3g 来解决。 
      打开ntfs-3g的下载点http://www.tuxera.com/community/ntfs-3g-download/ 

 

编译安装:

先进入源码存放位置

cd /usr/local/src/

下载当前最新版源码包

wget https://tuxera.com/opensource/ntfs-3g_ntfsprogs-2017.3.23.tgz

解压源码包

tar -zxvf ntfs-3g_ntfsprogs-2017.3.23.tgz

进入解压出来的文件包目录

cd ntfs-3g_ntfsprogs-2017.3.23

生成配置文件

./configure

编译

make

安装

make install

到此 安装结束

再来挂盘,本次挂U盘。

mount -t ntfs-3g /dev/sdb1 /mnt/usb

为什么我这里用  /dev/sdb1 这个就要用 fdisk -l  去看了

 

我这边是显示如下信息的

Disk /dev/sdb: 31.0 GB, 31029460992 bytes
255 heads, 63 sectors/track, 3772 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *         104        3716    29014016    7  HPFS/NTFS
/dev/sdb2            3716        3773      458751+  1b  Hidden W95 FAT32
 

所以我挂的是 sdb1 就是挂这个NTFS的

 

卸载u盘:在使用完u盘后,在拔出前需要先键入卸载U盘命令    
     命令如下:umount /mnt/usb

卸载之前,不要当前路径在U盘挂载下,要切到其他目录下 才可以正常卸载。

另外 如果要挂载我上面列出的 sdb2 则命令如下

 mount /dev/sdb2 /mnt/usb

 

整个测试我在  CentOS6.10下进行的。

本人微信:   本人QQ:

 

我们今天的关于PHP警告:POST Content-Length的8978294字节超出了第0行中Unknown中的8388608字节的限制的分享已经告一段落,感谢您的关注,如果您想了解更多关于android – 计算Base64编码文件的Post Content-Length的大小、CentOS ping: unknown host 解决方法、centOS 之 java.net.UnknownHostException: centos: centos: 未知的名称或服务、CentOS 挂载NTFS格式的U盘报 unknown filesystem type ‘ntfs’的相关信息,请在本站查询。

本文标签: