PHP: file_get_contents/file_put_contents 限制为 4KB

PHP: file_get_contents/file_put_contents limited to 4KB

我正在使用 MIT App Inventor post 我的应用程序库中的文件到服务器上的 PHP 文件。我一直在尝试将文件从图库写入服务器,但每个文件的大小一直限制在 4KB。我试过使用循环,显然没有用,我最近的尝试是:

$handle = fopen("php://input", "rb");
$fh = fopen("uploadedimages/" . $filename, 'wb');
if (FALSE === $handle) {
    exit("Failed to open stream to URL");
}
$contents = '';

while (!feof($handle)) {
 $contents .= fread($handle, 8192);
 $fh .= fwrite($fh, $contents);
}
fclose($fh);
fclose($handle);

还尝试了以下变体:

set_time_limit(0);
ini_set('memory_limit', '-1');

$remote_contents = file_get_contents("php://input");
file_put_contents("uploadedimages/" . $filename, $remote_contents);

关于我如何真正完成将远程图像完全写入服务器的任何建议?出于测试目的,服务器设置设置为荒谬的数量(上传为 100GB,max_post_data 为 10G 等)。

您的 php.ini 文件中有 3 个部分可以限制您尝试 'upload' 的图像大小。

memory_limit = 32M
upload_max_filesize = 10M
post_max_size = 20M

假设您可以访问 php.ini 文件。

如果没有,您也可以使用 .htaccess 文件覆盖这些设置

php_value upload_max_filesize 10M
php_value post_max_size 20M
php_value memory_limit 32M

不要忘记重新启动您的网络服务器以使更改生效

:)