我正在用 PHP 上传图像文件,但我发现无法获取从一台移动设备捕获的某些图像的文件大小。我可以获取文件名但不能获取文件大小,所以任何人都可以知道可能是什么问题或如何修复它以获得文件大小?当我检查系统中的大小时,它的大小以 MB 为单位,而我的其他图像以 KB 为单位。
<?php
if (isset($_FILES["file"]["name"][1]) && !empty($_FILES["file"]["name"])) {
$fileext = ["jpg", "jpeg", "png", "bif", "gif", "bmp"];
for ($i = 1; $i < count($_FILES["file"]["name"]); $i++) {
$name = $_FILES["file"]["name"][$i];
$type = $_FILES["file"]["type"][$i];
$size = $_FILES["file"]["size"][$i];
$path = $_FILES["file"]["tmp_name"][$i];
$ext = end(explode('.', strtolower($name)));
//checking file supported type
if (in_array($ext, $fileext)) {
echo $name . "<br>";
} else {
echo "file type not supported!";
}
}
}
?>
您需要在 php.ini 中设置 upload_max_filesize 和 post_max_size 的值:
; Maximum allowed size for uploaded files.
upload_max_filesize = 40M
; Must be greater than or equal to upload_max_filesize
post_max_size = 40M
修改 php.ini 文件后,您需要重新启动 HTTP 服务器才能使用新配置。
ini_set('upload_max_filesize', '10M');
ini_set('post_max_size', '10M');
ini_set('max_input_time', 300);
ini_set('max_execution_time', 300);
也增加 memory_limit 可能有用..
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句