예제 #1
0
function upload($file_id, $folder = "", $ftype, $title, $date, $id, $assoctable = "", $colname = "", $uploader = "")
{
    global $dbh, $uploadErrors;
    if ($_FILES[$file_id]["error"] > 0) {
        $result = $uploadErrors[$_FILES[$file_id]["error"]];
        return array('', $result);
    }
    if (!$_FILES[$file_id]['name']) {
        return array('', 'No file specified');
    }
    if (!$_FILES[$file_id]['size']) {
        return array('', 'File is zero length');
    }
    if (!is_numeric($ftype)) {
        return array('', "No type specified ({$ftype})");
    }
    if (!strlen($title)) {
        return array('', 'No title specified');
    }
    if (!strlen($date)) {
        return array('', 'No date specified');
    }
    if (!strlen($assoctable)) {
        return array('', 'No table specified');
    }
    if (!strlen($colname)) {
        return array('', 'No colname specified');
    }
    if (!strlen($folder)) {
        return array('', 'No folder specified');
    }
    $ftypestr = ftype2str($ftype, $dbh);
    $path_parts = pathinfo($_FILES[$file_id]["name"]);
    $fileext = $path_parts['extension'];
    $unique = substr(uniqid(), -4, 4);
    $filefn = "{$ftypestr}-" . validfn($title) . "-{$unique}.{$fileext}";
    $filefn = strtolower($filefn);
    $uploadfile = $folder . $filefn;
    $result = '';
    //Move the file from the stored location to the new location
    if (!move_uploaded_file($_FILES[$file_id]['tmp_name'], $uploadfile)) {
        $result = "Cannot upload the file '" . $_FILES[$file_id]['name'] . "'";
        if (!file_exists($folder)) {
            $result .= " : Folder doesn't exist.";
        } elseif (!is_writable($folder)) {
            $result .= " : Folder not writable.";
        } elseif (!is_writable($uploadfile)) {
            $result .= " : File not writable.";
        }
        $filefn = '';
        return array($filefn, $result);
    }
    //else file was written
    //chmod($uploadfile,0777);//Make it universally writable.
    //add file to files table
    $datesec = ymd2sec($date);
    $sql = "INSERT into files (type,title,date,fname,uploader,uploaddate) VALUES ({$ftype},'{$title}','{$datesec}','{$filefn}','{$uploader}','" . time() . "')";
    db_exec($dbh, $sql);
    $lastid = $dbh->lastInsertId();
    //make association
    $sql = "INSERT into {$assoctable} ({$colname},fileid) VALUES ({$id},{$lastid})";
    db_exec($dbh, $sql);
    return array($filefn, $result);
}
예제 #2
0
    $imfn = "";
} else {
    $imfn = $_POST['imfn'];
}
/* csv field number to name mapping */
$fno2name = array('label', 'location', 'area', 'owner', 'status', 'dnsname', 'ipv4', 'comments', 'manufacturer', 'model', 'sn', 'itemtype', 'function', 'cpu', 'ram', 'hd');
$name2fno = array_flip($fno2name);
$nfields = count($fno2name);
//nextstep:
//0: show import form
//1: import file and if not successfull go to 0 else show imported file and fields, and candidate db objects
//2: DB insert
//echo "<p>NEXT1=$nextstep<br>";
if ($nextstep == 1 && strlen($_FILES['file']['name']) > 2) {
    //insert file
    $filefn = strtolower("import-" . $_COOKIE["itdbuser"] . "-" . validfn($_FILES['file']['name']));
    $uploadedfile = "{$tmpdir}/" . $filefn;
    $result = '';
    //Move the file from the stored location to the new location
    if (!move_uploaded_file($_FILES['file']['tmp_name'], $uploadedfile)) {
        $result = "Cannot upload the file '" . $_FILES['file']['name'] . "'";
        if (!file_exists($uploaddir)) {
            $result .= " : Folder doesn't exist.";
        } elseif (!is_writable($uploaddir)) {
            $result .= " : Folder not writable.";
        } elseif (!is_writable($uploadedfile)) {
            $result .= " : File not writable.";
        }
        $filefn = '';
        echo "<br><b>ERROR: {$result}</b><br>";
        $imfn = "";
예제 #3
0
         echo "<br><b>No file uploaded.</b><br>";
     }
 } else {
     $sql = "UPDATE locations set name='{$name}', floor='{$floor}' " . " WHERE id={$id}";
     db_exec($dbh, $sql);
     if (strlen($_FILES['file']['name']) > 2) {
         //update file
         $sql = "SELECT * from locations where id={$id}";
         $sth = db_execute($dbh, $sql);
         $rf = $sth->fetch(PDO::FETCH_ASSOC);
         $oldfname = $rf['floorplanfn'];
         $path_parts = pathinfo($_FILES['file']["name"]);
         $fileext = $path_parts['extension'];
         $ftypestr = ftype2str($_POST['type'], $dbh);
         $unique = substr(uniqid(), -4, 4);
         $filefn = strtolower("floorplan-" . validfn($name) . "-{$unique}.{$fileext}");
         $uploadfile = $uploaddir . $filefn;
         $result = '';
         //Move the file from the stored location to the new location
         if (!move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
             $result = "Cannot upload the file '" . $_FILES['file']['name'] . "'";
             if (!file_exists($uploaddir)) {
                 $result .= " : Folder doesn't exist.";
             } elseif (!is_writable($uploaddir)) {
                 $result .= " : Folder not writable.";
             } elseif (!is_writable($uploadfile)) {
                 $result .= " : File not writable.";
             }
             $filefn = '';
             echo "<br><b>ERROR: {$result}</b><br>";
         } else {
예제 #4
0
/* Spiros Ioannou 2009-2010 , sivann _at_ gmail.com */
if (isset($_POST['dosave']) && $_POST['dosave'] == 1) {
    //if we came from a post (save), save translation
    $lang = $_POST['lang'];
    $x = array();
    for ($i = 0; $i < $_POST['trcount']; $i++) {
        $n1 = "tr1_{$i}";
        $n2 = "tr2_{$i}";
        $x[] = html_entity_decode($_POST[$n1], ENT_QUOTES, 'UTF-8') . "#" . html_entity_decode($_POST[$n2], ENT_QUOTES, 'UTF-8') . "\n";
    }
    if (FALSE === file_put_contents("translations/" . $lang . ".txt", $x)) {
        echo "Error writing translations/" . $lang . ".txt";
    }
} elseif (isset($_POST['newlang']) && strlen($_POST['newlang'])) {
    $newfile = $_POST['newlang'] . ".txt";
    $newfile = validfn($newfile);
    if (file_exists("translations/{$newfile}")) {
        echo "<b>{$newfile} already exists, not overwritten!</b>";
    } elseif (!copy("translations/new.txt", "translations/{$newfile}")) {
        echo "<br>failed to copy {$newfile} to {$scriptdir}/translations/{$newfile}\n";
    } else {
        echo "<b><br>copied  {$newfile} to {$scriptdir}/translations/{$newfile}\n</b>";
    }
}
/////////////////////////////
//// display data
$sql = "SELECT * FROM settings";
$sth = $dbh->query($sql);
$settings = $sth->fetchAll(PDO::FETCH_ASSOC);
$settings = $settings[0];
if (isset($_POST['lang'])) {
예제 #5
0
<?php

exit;
//rename all license files
chdir("..");
require "init.php";
echo "<pre>";
/* Spiros Ioannou 2009 , sivann _at_ gmail.com */
$sql = "SELECT * from software ";
$sth = db_execute($dbh, $sql);
while ($r = $sth->fetch(PDO::FETCH_ASSOC)) {
    if (!strlen($r['slicensefile'])) {
        continue;
    }
    //if no file associated continue
    $path_parts = pathinfo($r["slicensefile"]);
    $ext = $path_parts['extension'];
    $dymd = strftime("%Y%m%d", $r['purchdate']);
    //new filename
    $slicensefilefn = "lic-" . validfn($r["scompany"]) . "-" . validfn($r["stitle"]) . "-" . validfn($r["sversion"]) . "-{$dymd}-" . $r['id'] . ".{$ext}";
    $slicensefilefn = strtolower($slicensefilefn);
    echo "will move '{$r['slicensefile']}' to '{$slicensefilefn}'\n";
    $ret = rename($uploaddir . $r['slicensefile'], $uploaddir . $slicensefilefn);
    if ($ret) {
        $sql = "UPDATE software set slicensefile='{$slicensefilefn}'  WHERE id='{$r['id']}'";
        db_exec($dbh, $sql);
    } else {
        echo "<b>ERROR moving </b><br>\n";
    }
}
예제 #6
0
<?php

exit;
//rename all invoice files
chdir("..");
require "init.php";
echo "<pre>";
/* Spiros Ioannou 2009 , sivann _at_ gmail.com */
$sql = "SELECT * from invoices ";
$sth = db_execute($dbh, $sql);
while ($r = $sth->fetch(PDO::FETCH_ASSOC)) {
    if (!strlen($r['fname'])) {
        continue;
    }
    //if no file associated continue
    $path_parts = pathinfo($r["fname"]);
    $invoiceext = $path_parts['extension'];
    $dymd = strftime("%Y%m%d", $r['date']);
    //new filename
    $invoicefn = "inv-" . validfn($r["vendor"]) . "-" . validfn($r["number"]) . "-{$dymd}-" . $r['id'] . ".{$invoiceext}";
    $invoicefn = strtolower($invoicefn);
    echo "will move {$r['fname']} to {$invoicefn}\n";
    $ret = rename($uploaddir . $r['fname'], $uploaddir . $invoicefn);
    if ($ret) {
        $sql = "UPDATE invoices set fname='{$invoicefn}'  WHERE id='{$r['id']}'";
        db_exec($dbh, $sql);
    } else {
        echo "<b>ERROR moving </b><br>\n";
    }
}
예제 #7
0
         exit;
     }
 } else {
     $sql = "UPDATE files set title='{$title}', type='{$type}', uploader='{$userdata[0]['username']}', uploaddate='" . time() . "', " . " date='{$date}' WHERE id={$id}";
     db_exec($dbh, $sql);
     if (strlen($_FILES['file']['name']) > 2) {
         //update file
         $sql = "SELECT * from files where id={$id}";
         $sth = db_execute($dbh, $sql);
         $r = $sth->fetch(PDO::FETCH_ASSOC);
         $oldfname = $r['fname'];
         $path_parts = pathinfo($_FILES['file']["name"]);
         $fileext = $path_parts['extension'];
         $ftypestr = ftype2str($_POST['type'], $dbh);
         $unique = substr(uniqid(), -4, 4);
         $filefn = strtolower("{$ftypestr}-" . validfn($title) . "-{$unique}.{$fileext}");
         $uploadfile = $uploaddir . $filefn;
         $result = '';
         //Move the file from the stored location to the new location
         if (!move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
             $result = "Cannot upload the file '" . $_FILES['file']['name'] . "'";
             if (!file_exists($uploaddir)) {
                 $result .= " : Folder doesn't exist.";
             } elseif (!is_writable($uploaddir)) {
                 $result .= " : Folder not writable.";
             } elseif (!is_writable($uploadfile)) {
                 $result .= " : File not writable.";
             }
             $filefn = '';
             echo "<br><b>ERROR: {$result}</b><br>";
         } else {