Location: PHPKode > projects > Druid Defect Control > defectcontrol_0.9.4/tts/uploadattachpost.php
<?php ob_start();

require_once 'database.php'; 
require_once 'usercheck.php';
require_once 'history.php';
require_once 'errors.php';

    // connect to the db
    ttdb_connect($connection);
    ttdb_beginTransaction($connection);

    /*
    echo $HTTP_POST_FILES['userfile']['name']."<BR>";
    echo $HTTP_POST_FILES['userfile']['type']."<BR>";
    echo $HTTP_POST_FILES['userfile']['size']."<BR>";
    echo $HTTP_POST_FILES['userfile']['tmp_name']."<BR>";
    */

    // check if directory exists
    if (stat(ATTACHMENTS_BASE_DIR."/$iddefect") == FALSE) {
        // create directory
        mkdir (ATTACHMENTS_BASE_DIR."/$iddefect", 0700);
        //echo "Created directory<br>";
    }

    $hr = move_uploaded_file($userfile, ATTACHMENTS_BASE_DIR."/$iddefect/{$HTTP_POST_FILES['userfile']['name']}");
    //echo "File moved there<br>";

    if ($hr == false) {
        tter_errorWithBackButton("Could not store the uploaded file. ".
            "Verify with the administrator that php can write in the attachments ".
            "directory.");
        exit();
    }

    $attId = ttdb_getSequenceValue($connection, 'attachment');    

    $query = "INSERT INTO attachments (iid, iiddefect, sdescription, sfile, ".
        "smimetype) VALUES ($attId, $iddefect, '$fFileDesc', ".
        "'{$HTTP_POST_FILES['userfile']['name']}', ".
        "'{$HTTP_POST_FILES['userfile']['type']}')";

    echo $query;
    ttdb_execQuery($connection, $query);
    

    tt_historyEntry($connection, $iddefect, "Added attachment \"$fFileDesc\" by $ddts_username");    

    // go to the VisualizeForm page
    ttdb_commitTransaction($connection);
    ttdb_close($connection);
    
    header("Location: visualize.php?iddefect=$iddefect");
    ob_end_flush();
?>
Return current item: Druid Defect Control