I am about done writing this class for malshare.com’s API. Super easy. When I run the CURL command in my terminal, works great. I started converting it into PHP and it doesn’t return any data, it must be working since it’s returning true.
function upload($file)
{
$url = "https://malshare.com/api.php?api_key=".$this->api_key."&action=upload";
$post_data = [
"upload" => $file
];
$options = [
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $post_data
];
$ch = curl_init();
curl_setopt_array($ch, $options);
$data = curl_exec($ch);
}
However, I get no data and even the CURL info block doesn’t tell me shit, what am I doing wrong here?! it looks fine to me. Below is the curl_info()
Array
(
[url] => https://malshare.com/api.php?api_key=6d9b0d0236-----------------5d9742a3&action=upload
[content_type] => text/html; charset=UTF-8
[http_code] => 200
[header_size] => 156
[request_size] => 275
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.201478
[namelookup_time] => 0.012428
[connect_time] => 0.041186
[pretransfer_time] => 0.137284
[size_upload] => 155
[size_download] => 0
[speed_download] => 0
[speed_upload] => 769
[download_content_length] => 0
[upload_content_length] => 155
[starttransfer_time] => 0.168639
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => 173.254.233.139
[certinfo] => Array
(
)
[primary_port] => 443
[local_ip] => 192.168.10.106
[local_port] => 45374
)
and here is the full class
<?php
class Malshare
{
private $api_key;
private $url = "https://malshare.com/";
private $endpoint;
//make a new malshare
function __construct($key)
{
$this->api_key = $key;
}
//make a call to the API endpoint
function makeCall($ep)
{
return file_get_contents($ep);
}
//api.php?api_key=[API_KEY]&action=getlist
function listHashesJson()
{
$this->endpoint = "api.php?api_key=".$this->api_key."&action=getlist";
return $this->makeCall($this->url.$this->endpoint);
}
//api.php?api_key=[API_KEY]&action=getlistraw
function listHashesRaw()
{
$this->endpoint = "api.php?api_key=".$this->api_key."&action=getlistraw";
return $this->makeCall($this->url.$this->endpoint);
}
///api.php?api_key=[API_KEY]&action=getsources
function getSourcesJson()
{
$this->endpoint = "api.php?api_key=".$this->api_key."&action=getsources";
return $this->makeCall($this->url.$this->endpoint);
}
///api.php?api_key=[API_KEY]&action=getsourcesraw
function getSourcesRaw()
{
$this->endpoint = "api.php?api_key=".$this->api_key."&action=getsourcesraw";
return $this->makeCall($this->url.$this->endpoint);
}
///api.php?api_key=[API_KEY]&action=getfile&hash=[HASH]
function dlFile($hash)
{
$this->endpoint = "api.php?api_key=".$this->api_key."&action=getfile&hash=".$hash;
file_put_contents($hash, fopen($this->url.$this->endpoint, 'r'));
}
///api.php?api_key=[API_KEY]&action=details&hash=[HASH]
function getFileDetails($hash)
{
$this->endpoint = "api.php?api_key=".$this->api_key."&action=details&hash=".$hash;
return $this->makeCall($this->url.$this->endpoint);
}
///api.php?api_key=[API_KEY]&action=type&type=[FILE TYPE]
//types: md5|sha1|sha256
function listHashesByType($type)
{
$this->endpoint = "api.php?api_key=".$this->api_key."&action=type&type=".$type;
return $this->makeCall($this->url.$this->endpoint);
}
///api.php?api_key=[API_KEY]&action=search&query=[SEARCH QUERY]
function search($q)
{
$this->endpoint = "api.php?api_key=".$this->api_key."&action=search&query=".$q;
return $this->makeCall($this->url.$this->endpoint);
}
///api.php?api_key=[API_KEY]&action=gettypes
function getTypes()
{
$this->endpoint = "api.php?api_key=".$this->api_key."&action=gettypes";
return $this->makeCall($this->url.$this->endpoint);
}
///api.php?api_key=[API_KEY]&action=upload
function upload($file)
{
$url = $this->url."api.php?api_key=".$this->api_key."&action=upload";
$post_data = [
"upload" => $file
];
$options = [
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $post_data
];
$ch = curl_init();
curl_setopt_array($ch, $options);
$data = curl_exec($ch);
return $data;
}
///api.php?api_key=[API_KEY]&action=getlimit
function getLimit()
{
$this->endpoint = "api.php?api_key=".$this->api_key."&action=getlimit";
return $this->makeCall($this->url.$this->endpoint);
}
}
?>