开发者

Making my image uploading code DRY with PHP

开发者 https://www.devze.com 2023-04-11 05:32 出处:网络
I\'m using PHP to upload a pdf. I now have to edit the code to upload up to 5 PDFs, each with a different input and name. I\'d like to alter the code so it loops through 5 times once for each of the 5

I'm using PHP to upload a pdf. I now have to edit the code to upload up to 5 PDFs, each with a different input and name. I'd like to alter the code so it loops through 5 times once for each of the 5 inputs.

The input names are uploadedpdf1, uploadedpdf2, uploadedpdf3, uploaded4, & uploadedpdf5.

The current code is as follows.

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 t开发者_如何学Co get the file extension

}

How can I alter this to loop through 5 times with only the '1' at the end of'uploadedpdf altered?


for ($i = 1; $i < 6; ++$i) {
    $file = "uploadedpdf{$i}";
    // do things with $_FILES[$file]
}
0

精彩评论

暂无评论...
验证码 换一张
取 消