Browse Source

allow uploading multiple files at once

master
Fabian Kurz 2 years ago
parent
commit
575b9e4763
  1. 20
      api.php
  2. 10
      functions.php
  3. 3
      help.php
  4. 8
      index.php

20
api.php

@ -91,16 +91,20 @@
}
function upload($ign) {
if (isset($_FILES['uploaded_file'])) {
$filename_original = $_FILES['uploaded_file']['name'];
$filename_local = "/tmp/".md5(time() . $filename_original . rand(1,999));
error_log("Upload $filename_original to $filename_local");
error_log(print_r($_FILES, TRUE));
if (move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $filename_local)) {
error_log("move ok. ign = $ign");
echo import(file_get_contents($filename_local), $_SESSION['callsign'], $ign);
$ret = "";
foreach ($_FILES["uploaded_files"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$filename_original = $_FILES['uploaded_files']['name'][$key];
$filename_local = "/tmp/".md5(time() . $filename_original . rand(1,999));
error_log("Upload $filename_original to $filename_local");
if (move_uploaded_file($_FILES['uploaded_files']['tmp_name'][$key], $filename_local)) {
error_log("move ok. ign = $ign");
$ret .= import($filename_original, file_get_contents($filename_local), $_SESSION['callsign'], $ign);
}
}
}
echo $ret;
}
function save() {

10
functions.php

@ -305,10 +305,10 @@ function wae($c, $b) {
# If ign is set, ignore DXCC, WAZ and State info from the uploaded log
function import($adif, $callsign, $ign) {
function import($filename, $adif, $callsign, $ign) {
global $db;
$ret = "Starting import for $callsign...<br>";
$ret = "<br>Starting import ($filename) for $callsign...<br>";
$members = get_memberlist();
$ret .= "Loaded member list with ".count($members)." entries.<br>";
@ -342,9 +342,11 @@ function import($adif, $callsign, $ign) {
$qsos = filter_qsos($qsos, $callsign);
$ret .= "Imported ".count($qsos)." QSOs which were new for award purposes.<br>";
$ret .= "Full log of the import below. <a href='#' onClick='javascript:document.getElementById(\"import_log\").style.display = \"none\";'>Click here to hide</a>";
$nr = rand(0,10000);
$ret .= "<pre id='import_log'>";
$ret .= "Full log of the import below. <a href='#' onClick='javascript:document.getElementById(\"import_log$nr\").style.display = \"none\";'>Click here to hide</a>";
$ret .= "<pre id='import_log$nr'>";
$import_log = "";
foreach ($qsos as $q) {
$import_log .= "QSO: ".$q['call']." ".$q['date']." ".$q['band']." needed for: ".$q['reasons']."<br>";

3
help.php

@ -35,6 +35,9 @@
<p>There's a checkbox on the log upload form saying "Take DXCC, WAZ and WAS values from the database (not from ADIF; recommended)". If this is checked, the application will try to resolve DXCCs, CQ zones (WAZ) and states by means of OK1RR's country files and the CWops member database. If it's not checked, it will blindly accept any values that your logger wrote into the ADIF file. From experience, the quality of exported data from many loggers isn't very good. More often than not, CQ and ITU zones are swapped, or some more exotic DXCC prefixes are not recognized as such.</p>
<p>Therefore the recommendation (and default) is to keep this box checked.</p>
<h2>Can I upload multiple files at once?</h2>
<p>Yes, in the file open dialog, simply select more than one file by clicking on them while keeping the Ctrl key pressed.</p>
<h2>Thanks</h2>
<p>Thanks to the following individuals for their help and contributions during the beta testing phase:</p>
<ul>

8
index.php

@ -21,7 +21,7 @@ if (array_key_exists("id", $_SESSION)) {
<p>Logged in as <?=$_SESSION['callsign'];?>. <a href="/logout">Log out</a></p>
<P>Upload new ADIF, CAM or Cabrillo log:
<input type="file" id="file" /> <button id='upload' onClick='javascript:upload();'>Upload</button>
<input type="file" id="file" multiple /> <button id='upload' onClick='javascript:upload();'>Upload</button>
<input id="cbignore" type="checkbox" name="cbignore" value="1" checked> Take DXCC, WAZ and WAS values from the database (not from ADIF; recommended)
</p>
@ -47,7 +47,11 @@ if (array_key_exists("id", $_SESSION)) {
var f = document.getElementById('file');
var file = f.files[0];
var data = new FormData();
data.append("uploaded_file", file);
for (var x = 0; x < f.files.length; x++) {
data.append("uploaded_files[]", f.files[x]);
}
var request = new XMLHttpRequest();
request.open("POST", '/api?action=upload&ign=' + (ign ? '1' : '0'), true);
request.onreadystatechange = function() {

Loading…
Cancel
Save