Commit 13e080c6 authored by alexm98's avatar alexm98

Converting IPFS output to hex, and checking the magic numbers for finding the mimetype.

parent fe702337
......@@ -13,6 +13,33 @@ class FileController extends Controller
$this->ipfs = new IPFS('localhost', '8080', '5001');
}
public function byte2hex($bytes){
$hexstr = unpack('H*', $bytes);
return array_shift($hexstr);
}
public function getMime($hash){
$obj = $this->ipfs->cat($hash);
$hex = strtoupper(self::byte2hex($obj));
$mimes = [
'PDF' => '25504446',
'PNG' => '89504E470D0A1A0A',
'GIF' => '474946383961',
];
foreach($mimes as $key=>$value){
if(strpos($hex,$value) !== FALSE){
echo $key;
}
}
}
public function setMimeHeader(){
// set correct header for showing the data type
}
/**
* Display a listing of the resource.
*
......@@ -52,7 +79,8 @@ class FileController extends Controller
*/
public function show($hash)
{
echo $this->ipfs->cat($hash);
// echo $this->ipfs->cat($hash);
self::getMime($hash);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment