forked from royhodge/apps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvault_upload_process.php
More file actions
56 lines (47 loc) · 1.78 KB
/
Copy pathvault_upload_process.php
File metadata and controls
56 lines (47 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
session_start();
ob_start();
require_once('check-login.php');
include_once "config.php";
include_once "resources.php";
include_once "dbhelper.php";
try
{
if(isset($_POST["dou"]))
{
$uploader_address = $_SESSION['address'];
$dateOfUpload = DateTime::createFromFormat('Y-m-d H:i:s',str_replace("T", " ", $_POST["dou"]));
$dateOfUploadStr = $dateOfUpload->format('d-M-Y H:i:s');
$desc = isset($_POST["desc"])?$_POST["desc"]:"";
$file = $_FILES['filename'];
$target_file = $_FILES['filename']['tmp_name'];
/// Reading file contents
$handle = fopen($target_file, "rb");
$file_bin_data = fread($handle, filesize($target_file));
$file_bin_data = file_to_txout_bin($_FILES['filename']['name'], $_FILES['filename']['type'], $file_bin_data);
$fileContentHex = bin2hex($file_bin_data);
fclose($handle);
$contentArr = array(
Literals::VAULT_FIELDS_CODES['date_of_upload'] => $dateOfUploadStr,
Literals::VAULT_FIELDS_CODES['description'] => $desc,
Literals::VAULT_FIELDS_CODES['file_hex'] => $fileContentHex
);
$contentJSON = json_encode($contentArr);
$contentHex = bin2hex($contentJSON); /// Hex encoding the metadata
$streamKey = hash_file('sha256', $target_file);
unlink($target_file);
$dbHelper = new DBHelper();
$txId = $dbHelper->uploadDocumentToVault($uploader_address, $streamKey, $contentHex); /// Publisher address and stream name to be modified
echo "<b><font color='green'>Transaction Successful.<br/>"."Your Transaction ID is </font></b>"."<a href='vault_upload_transaction_details.php?txid=".$txId."'>".$txId."</a>";
}
else
{
throw new Exception("Error Processing Request");
}
}
catch (exception $ex)
{
echo "<font color='red'><b>".$ex->getMessage()."</b></font>";
}
ob_end_flush();
?>