コード例 #1
0
ファイル: multi_upload.php プロジェクト: helenadeus/s3db.map
 include_once 'core.header.php';
 #include_once('s3dbcore/transferFile.php');
 if (!$_FILES) {
     echo formatReturn('3', 'No file to upload.', $_REQUEST['format'], '');
     exit;
 } elseif ($file_id == '') {
     if (is_array($_FILES)) {
         $folder = $GLOBALS['s3db_info']['server']['db']['uploads_folder'] . $GLOBALS['s3db_info']['server']['db']['uploads_file'] . '/tmps3db/';
         $filekey = '';
         $filename = '';
         foreach ($_FILES as $inputName => $fileData) {
             ereg('.*\\.([a-zA-Z0-9]*)$', $_FILES[$inputName]['name'], $ext);
             $ext = $ext[1];
             $filename = $_FILES[$inputName]['name'];
             $filesize = $_FILES[$inputName]['size'];
             $filekey = generateAFilekey(compact('filename', 'filesize', 'db', 'user_id'));
             #Retrieve the file_id fro mthe filekey
             $tmp = get_filekey_data($filekey, $db);
             $file_id = $tmp['file_id'];
             ##Now upload the file
             $final = $folder . $file_id . '.' . $ext;
             $moved = copy($_FILES[$inputName]['tmp_name'], $final);
             if ($moved) {
                 ##Was a rule_id and item_id provided? If yes, insert it using s3ql, if not, provide the filekey
                 if ($_REQUEST['item_id'] && $_REQUEST['rule_id']) {
                     $s3ql = compact('user_id', 'db');
                     $s3ql['insert'] = 'file';
                     $s3ql['where']['item_id'] = $_REQUEST['item_id'];
                     $s3ql['where']['rule_id'] = $_REQUEST['rule_id'];
                     $s3ql['where']['filekey'] = $filekey;
                     $s3ql['format'] = $_REQUEST['format'];
コード例 #2
0
ファイル: move2s3db.php プロジェクト: helenadeus/s3db.map
function move2s3db($toMove, $db, $user_id)
{
    #toMove is an array with file, item_id and rule_id, for example $toMove=compact('file','item_id','rule_id');
    ##
    #encode the file in base64. Break it in 1084 (1Mb) pieces
    $fid = fopen($toMove['file'], 'r');
    #$fSize = 10000;
    $fSize = filesize($toMove['file']);
    ##=>to change once I find a way to palce the pointer at the end of the file
    $parts = ceil(filesize($toMove['file']) / $fSize);
    $filekey = generateAFilekey(array('filename' => $toMove['file'], 'filesize' => filesize($toMove['file']), 'db' => $db, 'user_id' => $user_id));
    for ($i = 1; $i <= $parts; $i++) {
        $fileStr = base64_encode(fread($fid, $fSize));
        $fragNr = $i . '/' . $parts;
        #echo "sending frag ".$fragNr.chr(10);
        ###
        #send this piece to the local deployment as a file
        if ($fileStr != '') {
            $received = receiveFileFragments(compact('filekey', 'db', 'fileStr', 'fragNr'));
        }
    }
    $s3ql = compact('user_id', 'db');
    $s3ql['insert'] = 'file';
    $s3ql['where']['filekey'] = $filekey;
    $s3ql['where']['rule_id'] = $toMove['rule_id'];
    $s3ql['where']['item_id'] = $toMove['item_id'];
    $fileinserted = S3QLaction($s3ql);
    $fileinserted = html2cell($fileinserted);
    return $fileinserted;
}
コード例 #3
0
ファイル: insertall.php プロジェクト: helenadeus/s3db.map
function render_inserted_statement_all($I)
{
    extract($I);
    $_SESSION['current_color'] = '0';
    $_SESSION['previous_verb'] = '';
    $instance_id = $instance_info['resource_id'];
    $stats = '';
    if (is_array($rules)) {
        foreach ($rules as $rule_info) {
            $report_msg = '';
            $subject = $rule_info['subject'];
            $verb = $rule_info['verb'];
            $object = $rule_info['object'];
            $rule_id = $rule_info['rule_id'];
            $rule_notes = $rule_info['notes'];
            $notes = $_POST['text_' . $instance_id . '_' . $rule_id];
            $index = $index + 1;
            if (in_array($rule_id, $rule_ids)) {
                #echo 'upload_input_'.$instance_id.'_'.$rule_id.'<BR>';
                #gather data from post
                if ($_FILES['upload_input_' . $instance_id . '_' . $rule_id]['name'] == '') {
                    $value = $_POST['input_' . $instance_id . '_' . $rule_id];
                    if ($value == '') {
                        $value = $_POST['input_' . str_replace('.', '_', $instance_id) . '_' . str_replace('.', '_', $rule_id)];
                    }
                    #insert the statement, run S3QL
                    $s3ql = compact('db', 'user_id');
                    $s3ql['insert'] = 'statement';
                    #$s3ql['where']['project_id'] = $project_id;
                    $s3ql['where']['item_id'] = $instance_id;
                    $s3ql['where']['rule_id'] = $rule_id;
                    $s3ql['where']['value'] = $value;
                    $s3ql['where']['notes'] = $notes;
                    #$s3ql['format']='html';
                    $done = S3QLaction($s3ql);
                    $done = html2cell($done);
                    #ereg('<error>([0-9]+)</error>.*<(message|statement_id)>(.*)</(message|statement_id)>', $done, $s3qlout);
                    $statement_id = $done[2]['statement_id'];
                    $S = compact('user_id', 'rule_info', 'instance_id', 'statement_id', 'value', 'notes', 'db', 'done');
                    if ($done[2]['error_code'] == '0') {
                        $report_msg = render_inserted($s3ql, $statement_id);
                        #$report_msg .= sprintf("%s\n", '		<br /><input type="button" value="Insert Another" onClick="window.location=\''.$action['instanceform'].'\'">');
                        #$report_msg .= sprintf("%s\n", '		<br /><input type="button" value="Close Window" onClick="window.location=\''.$action['instanceform'].'\'">');
                    } else {
                        $report_msg = couldnot_insert_statement($S);
                        #render_statement_already_exists($s3ql);
                    }
                    #elseif($s3qlout[1]=='7')
                    #{
                    #$report_msg = render_resource_doesnot_exist($s3ql);
                    #}
                    #elseif($s3qlout[1]=='3')
                    #{
                    #$report_msg = render_value_cannot_be_null($s3ql);
                    #}
                } else {
                    #project is the same that will go to instance
                    $project_id = $rule_info['project_id'];
                    $value = project_folder_name($project_id, $db);
                    $notes = $_REQUEST['text_' . $instance_id . '_' . $rule_id];
                    $filename = $_FILES['upload_input_' . $instance_id . '_' . $rule_id]['name'];
                    $mimetype = $_FILES['upload_input_' . $instance_id . '_' . $rule_id]['type'];
                    $filesize = filesize($_FILES['upload_input_' . $instance_id . '_' . $rule_id]['tmp_name']);
                    $uploadedfile = $_FILES['upload_input_' . $instance_id . '_' . $rule_id]['tmp_name'];
                    if ($filesize <= 0) {
                        $report_msg = 'Filesize cannot be null';
                    } elseif ($filename == '') {
                        $report_msg = 'Filename cannot be empty';
                    } elseif ($value == '' || $uploadedfile == '') {
                        $report_msg = 'Could not move file, please check with you administrator if file uploads are allowed.';
                    } else {
                        $tmp = fileNameAndExtension($filename);
                        extract($tmp);
                        #write a filekey to send the file by the API
                        $filekey = generateAFilekey(compact('filename', 'extension', 'filesize', 'user_id', 'db'));
                        #move the file like the API would do
                        $file = $uploadedfile;
                        $fileMoved = MoveFile(compact('filekey', 'db', 'file'));
                        #generate a statement_id
                        if ($fileMoved) {
                            $s3ql = compact('db', 'user_id');
                            $s3ql['insert'] = 'file';
                            $s3ql['where']['filekey'] = $filekey;
                            $s3ql['where']['notes'] = $notes;
                            $s3ql['where']['project_id'] = $project_id;
                            $s3ql['where']['rule_id'] = $rule_id;
                            $s3ql['where']['item_id'] = $instance_id;
                            $s3ql['format'] = 'html';
                            $done = S3QLaction($s3ql);
                            $done = html2cell($done);
                            #echo '<pre>';print_r($done);
                            #ereg('<statement_id>([0-9]+)</statement_id>', $done, $s3qlout);
                            $statement_id = $done[2]['file_id'];
                            if ($statement_id != '') {
                                $insert = 'file';
                                $S = compact('rule_id', 'instance_id', 'db', 'insert', 'filename');
                                $report_msg = render_inserted($S, $statement_id);
                            }
                        } else {
                            $report_msg = "<font color='red'>Could not move the file</font>";
                            exit;
                        }
                    }
                }
            } else {
                $report_msg = render_empty_form(compact('index', 'rule_info', 'project_id', 'instance_id', 'db'));
            }
            $finalOutput .= $report_msg;
        }
    }
    //echo $stats;
    return $finalOutput;
}
コード例 #4
0
ファイル: rdfWrite.php プロジェクト: helenadeus/s3db.map
function moveS3DBfileLink($stat_value, $db, $user_id)
{
    ereg('^s3dbLink_(.*)#(.*[^(_|")])$', $stat_value, $isLink);
    #Reading the link should give us the file contents
    if ($isLink) {
        $link = $isLink[2];
        $fid = stream_get_contents(fopen($link, 'r'));
        if ($fid == '') {
            return "Could not open the file.";
        }
    }
    $filename = $isFile[1];
    $fileNewPath = $isFile[2];
    if (!is_file($fileNewPath)) {
        return 'File not found';
    }
    #chdir($GLOBALS['s3db_info']['server']['db']['uploads_folder'].$GLOBALS['s3db_info']['server']['db']['uploads_file'].'/tmps3db/');
    $filesize = filesize($fileNewPath);
    #write a filekey to send the file by the API
    $filekey = generateAFilekey(compact('filename', 'filesize', 'db', 'user_id'));
    #move the file like the API would do
    $dest = findDestFile(compact('filekey', 'db', 'user_id'));
    if (copy($fileNewPath, $dest)) {
        #unlink($fileNewPath);
        #rename($fileNewPath, $fileNewPath.'_moved');
        return $filekey;
    }
}