-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathipfshandler.php
More file actions
68 lines (57 loc) · 2.31 KB
/
ipfshandler.php
File metadata and controls
68 lines (57 loc) · 2.31 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
58
59
60
61
62
63
64
65
66
67
68
<?php
error_reporting(E_ALL);
if(isset($_POST["url"])){
$target_url = "http://127.0.0.1:5001/api/v0/add?stream-channels=true&pin=false&wrap-with-directory=true&arg=/file&progress=false";
$content = file_get_contents($_POST["url"]);
foreach($http_response_header as $header ){
echo $header;
}
$post = array('file' => $content);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $target_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result = curl_exec($ch);
curl_close($ch);
header("Content-Type: application/json");
// header("Content-Type: text/plain");
$cpUrl = "http://127.0.0.1:5001/api/v0/files/cp?arg=/ipfs/" . json_decode(explode("\n", $result)[0])->Hash . "&arg=/files/" . time() . ".";
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, $cpUrl);
curl_setopt($ch2, CURLOPT_POST, 1);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
$result2 = curl_exec($ch2);
curl_close($ch2);
echo ((explode("\n", $result)[0]));
// echo "\n\n";
// print_r($result2);
exit();
}
if ($_FILES["uploadfile"]["error"] == 0) {
$target_url = "http://127.0.0.1:5001/api/v0/add?stream-channels=true&pin=false&wrap-with-directory=true&arg=/file&progress=false";
$content = file_get_contents($_FILES["uploadfile"]["tmp_name"]);
$post = array('file' => $content);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $target_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result = curl_exec($ch);
curl_close($ch);
header("Content-Type: application/json");
// header("Content-Type: text/plain");
$cpUrl = "http://127.0.0.1:5001/api/v0/files/cp?arg=/ipfs/" . json_decode(explode("\n", $result)[0])->Hash . "&arg=/files/" . time() . "." . end(explode(".", $_FILES["uploadfile"]["name"]));
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, $cpUrl);
curl_setopt($ch2, CURLOPT_POST, 1);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
$result2 = curl_exec($ch2);
curl_close($ch2);
echo ((explode("\n", $result)[0]));
// echo "\n\n";
// print_r($result2);
exit();
}
http_response_code(413);
//print_r($_FILES);