2011-10-05 31 views
0

我使用PHP上傳PDF。我現在必須編輯代碼才能上傳最多5個PDF,每個都有不同的輸入和名稱。我想修改代碼,以便5次輸入每次循環5次。使我的圖像上傳代碼干與PHP

輸入名稱上傳.pdf1,uploadedpdf2,uploadedpdf3,上傳4,& 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 

} 

我該如何改變這個循環5次,在'uploadedpdf'末尾只有'1'被修改?

回答

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