forked from royhodge/apps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontract_upload_process.php
More file actions
57 lines (48 loc) · 1.7 KB
/
Copy pathcontract_upload_process.php
File metadata and controls
57 lines (48 loc) · 1.7 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
57
<?php
session_start();
ob_start();
require_once('check-login.php');
include_once "config.php";
include_once "resources.php";
include_once "dbhelper.php";
include_once "helperFunctions.php";
try
{
if(isset($_POST["dou"]))
{
$dateOfUpload = DateTime::createFromFormat('Y-m-d H:i:s', str_replace("T", " ", $_POST["dou"]));
}
else
{
$dateOfUpload = DateTime::createFromFormat('Y-m-d H:i:s', date('Y-m-d H:i:s'));
}
$uploaderAddress = $_SESSION['address'];
$uploaderID = $_SESSION['user_name'];
$dateOfUploadStr = $dateOfUpload->format('d-M-Y H:i:s');
$title = isset($_POST["title"])?$_POST["title"]:"";
$desc = isset($_POST["desc"])?$_POST["desc"]:"";
$file = $_FILES['filename'];
$target_file = $_FILES['filename']['tmp_name'];
/// Reading file contents
$handle = fopen($target_file, "rb");
$fileContentHex = bin2hex(fread($handle, filesize($target_file)));
fclose($handle);
$fileHash = hash_file('sha256', $target_file);
unlink($target_file);
$dbHelper = new DBHelper();
$contractID = generateGUID();
if($dbHelper->uploadContract($contractID, $uploaderAddress, $title, $dateOfUploadStr, $desc, $fileHash, $fileContentHex))
{
$signature = $dbHelper->signMessage($uploaderAddress, $fileHash);
$txIDSign = $dbHelper->signContract($contractID, $uploaderID, $uploaderAddress, $signature);
echo "<b><font color='green'>Transaction Successful.<br/>"."Your Contract ID is </font></b>"."<a target='_new' href='contract_upload_details.php?contractid=".$contractID."'>".$contractID."</a>";
}
else {
throw new Exception("Contract upload failed", 1);
}
}
catch (exception $ex)
{
echo "<font color='red'><b>".$ex->getMessage()."</b></font>";
}
?>