Example #1
0
function upload_file()
{
    if (strlen($_FILES['attachment']['tmp_name']) > 0) {
        $str = file_to_str($_FILES['attachment']['tmp_name'], $_FILES['attachment']['size']);
    } else {
        echo 'nothing to upload';
        return;
    }
    $link = mysql_connect('127.0.0.1', $_SESSION['login'], $_SESSION['password']);
    mysql_select_db('attachment', $link);
    if ($_POST['_attachment_id'] > 0) {
        $sql = 'update attachment set attachment=\'' . $str . '\' , attachment_name=\'' . $_FILES['attachment']['name'] . '\' 
				where id=\'' . $_POST['_attachment_id'] . '\'';
        //echo $sql.'<br>';
        if (!($result = mysql_query($sql, $link))) {
            echo mysql_error();
        }
        echo mysql_affected_rows($link) . ' rows updated in attachment table of attachment database<br>';
        //no need to update the link to original database
    } else {
        $sql = 'insert into attachment values(\'\', \'' . $str . '\' , \'' . $_FILES['attachment']['name'] . '\')';
        //echo $sql.'<br>';
        if (!($result = mysql_query($sql, $link))) {
            echo mysql_error();
        }
        $attachment_id = mysql_insert_id($link);
        echo 'id of new upload is ' . $attachment_id . ' <br>';
        //save link in original database
        $wh = '';
        foreach ($_POST as $key => $value) {
            $chr = str_split($key);
            if ($chr[0] == '_' && $chr[1] == 'p' && $chr[2] == 'r' && $chr[3] == 'i' && $chr[4] == '_') {
                $field = '';
                for ($i = 5; $i < strlen($key); $i++) {
                    $field = $field . $chr[$i];
                }
                $wh = $wh . ' `' . $field . '`=\'' . $value . '\' and ';
            }
            $final_wr = substr($wh, 0, -4);
        }
        mysql_select_db($_POST['_database'], $link);
        $sql_link = 'update `' . $_POST['_tablename'] . '` set attach=\'' . $attachment_id . '\' where ' . $final_wr;
        //echo $sql_link.'<br>';
        if (!($result = mysql_query($sql_link, $link))) {
            echo mysql_error();
        }
        echo mysql_affected_rows($link) . ' rows updated in table ' . $_POST['_tablename'] . ' of  ' . $_POST['_database'] . ' database<br>';
    }
}
Example #2
0
function insert_attachment($array, $files)
{
    if (strlen($files['file']['tmp_name']) > 0) {
        $str = file_to_str($files['file']);
        $sql = 'insert into attachment values(
				\'' . $array['sample_id'] . '\', 
				\'' . $array['attachment_id'] . '\',
				\'' . $array['description'] . '\',
				\'' . $array['filetype'] . '\',
				\'' . $str . '\')';
        //echo $sql;
        $link = start_nchsls();
        if (!($result = mysql_query($sql, $link))) {
            echo mysql_error();
        } else {
            echo 'success';
        }
    } else {
        echo 'no file to attach<br>';
    }
}
Example #3
0
function upload_blob($tname, $field)
{
    $pri = find_primary($tname);
    $where_condition = ' ';
    foreach ($pri as $key => $value) {
        $where_condition = $where_condition . ' `' . $value . '`=\'' . $_POST[$value] . '\' and ';
    }
    $where_condition_final = substr($where_condition, 0, -4);
    $file_name = $field . '_name';
    //echo '<h3>'.$file_name.'</h3>';
    if (strlen($_FILES[$field]['tmp_name']) > 0) {
        $str = file_to_str($_FILES[$field]['tmp_name'], $_FILES[$field]['size']);
        $sql = 'update `' . $tname . '` set ' . $field . '=\'' . $str . '\', ' . $file_name . '=\'' . $_FILES[$field]['name'] . '\' 
				where ' . $where_condition_final;
        //echo $sql;
        $link = start_nchsls();
        if (!($result = mysql_query($sql, $link))) {
            echo mysql_error();
        } else {
            echo 'upload is success<br>';
        }
    } else {
        echo 'nothing to upload';
    }
}