我正在使用PHP上传pdf。我现在必须编辑代码以上传最多5个PDF,每个PDF都有不同的输入和名称。我想改变代码,使其为5个输入中的每一个循环5次。
输入的名称是uploadpdf1,uploadedpdf2,uploadedpdf3,uploaded4,& uploadedpdf5。
目前的代码如下。
if($_FILES["uploadedpdf1"]["name"]!="") {
$fileName = $_FILES["uploadedpdf1"]["name"]; // The file name
$fileTmpLoc = $_FILES["uploadedpdf1"]["tmp_name"]; // File in the PHP tmp folder
$fileType = $_FILES["uploadedpdf1"]["type"]; // The type of file it is
$fileSize = $_FILES["uploadedpdf1"]["size"]; // File size in bytes
$fileErrorMsg = $_FILES["uploadedpdf1"]["error"]; // 0 = false | 1 = true
$kaboom = explode(".", $fileName); // Split file name into an array using the dot
$fileExt = end($kaboom); // Now target the last array element to get the file extension
}
如果只更改了'uploadpdf'末尾的'1',我怎么能改变它循环5次?
答案 0 :(得分:3)
for ($i = 1; $i < 6; ++$i) {
$file = "uploadedpdf{$i}";
// do things with $_FILES[$file]
}