<form action="admin.php?page=post" method="post" enctype="multipart/form-data">
<div class="clearfix">
<label for="xlInput">Upload</label>
<div class="input">
APT: <input class="input-file" id="fileInput" name="apt" type="file"><br>
ILS: <input class="input-file" id="fileInput" name="ils" type="file"><br>
AWOS: <input class="input-file" id="fileInput" name="awos" type="file"><br>
TWR: <input class="input-file" id="fileInput" name="twr" type="file">
<span class="help-block">
Warning: this may take a long time depending on your internet connection. If you lose connection you will have to restart!
</span>
</div>
</div><input type="hidden" name="type" value="admin-records-files">
<div class="actions">
<input type="submit" class="btn primary" value="Upload"> <button type="reset" class="btn" onclick="history.go(-1)">Cancel</button>
</div>
</div>
</form>
and in admin.php?page=post (truely admin-post.php)
switch($_POST['type']){
case "admin-records-files":
if(empty($_FILES['ils']) && empty($_FILES['awos']) && empty($_FILES['apt']) && empty($_FILES['twr'])){
$page['content'] .= '<div class="alert-message error">
<p><strong>You must upload at least one file</strong>.</p>
</div><a href="#" onclick="history.go(-2)" class="btn large">Back</a>';
} else {
$error = "";
$dFiles = 0;
foreach($_FILES as $id => $file){
if($file['size'] > 0){
if($file['type'] != "text/plain"){
$error = "Files are invalid. Must be in a text/plain format";
break;
}
if(!empty($file['error']) && $file['error'] != UPLOAD_ERR_OK){
$error = $file['error'];
break;
}
if($id == "awos"){
$fileT = "AWOS.txt";
} elseif($id == "apt"){
$fileT = "APT.txt";
} elseif($id == "ils"){
$fileT = "ILS.txt";
} elseif($id == "twr"){
$fileT = "TWR.txt";
} else {
$error = "Invalid form detected";
break;
}
$result = move_uploaded_file($file['tmp_name'], 'inc/data/FAA/' . $fileT);
if(!$result){
$error = "There was an error moving the uploaded file: " . $fileT;
break;
}
$dFiles++;
}
}
if(!empty($error)){
$page['content'] .= '<div class="alert-message error"><p><strong>There was a problem uploading your files:</strong> ' . $error . '</p></div>
<a href="#" class="btn large" onclick"history.go(-2)">Back</a>';
} else {
$page['content'] .= '<div class="alert-message success"><p><strong>Your files have been uploaded.</strong> ' . $dFiles . ' files where uploaded.</p></div>
<a href="admin.php?page=records-update" class="btn large">Records update page</a>';
}
}
break;
}
Each time I press "Upload" without any files selected, it works. But whenever I upload a file with it, it outputs this error:
Undefined index: type in (the file) on line 7 (line one in what I provided)

New Topic/Question
Reply





MultiQuote





|