forked from loadmybowl/apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contract_file_download.php
49 lines (41 loc) · 1.2 KB
/
contract_file_download.php
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
<?php
session_start();
ob_start();
require_once('check-login.php');
require_once('dbhelper.php');
require_once('resources.php');
require_once('helperFunctions.php');
require_once('config.php');
try
{
if (isset($_GET['txid']))
{
$txId = $_GET['txid'];
$uploader_address = $_GET['publisher'];
$dbHelper = new DBHelper();
if (isset($_GET['v_n']))
{
$vOut_n = intval($_GET['v_n']);
$fileContentHex = $dbHelper->getTransactionMetadata($txId, $vOut_n);
}
else
{
throw new Exception("Invalid Request. Missing parameter(s)!!");
//$transaction = $dbHelper->getAddressTransaction($uploader_address, $txId);
//$fileContentHex = $dbHelper->getDataFromDataItem($transaction['data'][1]);
}
$fileSignature = strtoupper(substr($fileContentHex, 0, 20));
$fileDataType = getFileDataType($fileSignature);
$downloadURL = "data:".$fileDataType.";base64,".base64_encode(pack('H*', $fileContentHex));
echo "<script>window.onload=function(){window.open('".$downloadURL."', '_self')}</script>";
}
else
{
throw new Exception("No Transaction ID found.");
}
}
catch(Exception $e)
{
echo "<h3 style='color:red'>".$e->getMessage()."</h3>";
}
?>