我使用这个 php 代码一次上传多个文件问题是我只能上传20个文件我不能一次上传多个文件
php代码
<?php
include("../includes/connect.php");
if (strtolower($_SERVER['REQUEST_METHOD']) !== 'post') header('Location:test.php');
date_default_timezone_set('Asia/Beirut');
$date=date('Y-m-d H:i:s');
$username=$_SESSION['user'];
$parentID = !empty($_GET['parentID']) ? $_GET['parentID'] : 0;;
$parent_id=intval($_GET['parentID']);
$valid_formats = array("jpg", "png", "gif", "zip","PNG","jpeg","bmp","pdf", "doc", "docx","xlsx","xls","txt","csv","pptx","ppt","pptm","dwg","rtf");
$max_file_size = 1024*100; //100 kb
$path = "../uploads_images/"; // Upload directory
$count = 0;
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
// Loop $_FILES to exeicute all files
foreach (preg_replace('/ /','-',($_FILES['myfile']['name'])) as $f => $name) {
if ($_FILES['myfile']['error'][$f] == 4) {
continue; // Skip file if any error found
}
if ($_FILES['myfile']['error'][$f] == 0) {
if( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){
$message[] = "$name is not a valid format";
continue; // Skip invalid file formats
}
else{ // No error found! Move uploaded files $sql=mysqli_query($conn,"select name from tbl_files where name='$name'")or die(mysqli_error($conn));
$countfile=mysqli_num_rows($sql);
if($countfile==0){
if(move_uploaded_file($_FILES["myfile"]["tmp_name"][$f], $path.$name))
$query=mysqli_query($conn,"INSERT INTO tbl_files(name,parent_id,db_username,db_date,db_isdeleted)VALUES('$name','$parent_id','$username','$date','0')") or die(mysqli_error($conn));
$count++; // Number of successfully uploaded file
header("location:dms.php?parentID=$parent_id&view");
}else{header("location:dms.php?parentID=$parent_id&msg=3&view");}
}
}
}
}
?>
谷歌搜索后发现我需要更改 upload_max_filesize 我这样做了我改为1G像这样 upload_max_filesize = 1G 但是同样的问题仍然存在 我在 php.ini
中改变了什么memory_limit的= 256M
的post_max_size = 1G
的upload_max_filesize = 64M
我在 godaddy
中使用托管和域名最后问题是我如何解决我的问题,并且能够一次上传无限文件?!!
答案 0 :(得分:1)
变化
max_file_uploads=20
到你想要的任何数字。如
max_file_uploads=200
别忘了重启服务器。