I scan files from folder ($cfile has fake content intentionally)
$api_key = getenv('VT_API_KEY') ? getenv('VT_API_KEY') :$this->_key;
$cfile = 'asdasdas';
$post = array('apikey' => $api_key,'file'=> $cfile);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.virustotal.com/vtapi/v2/file/scan');
curl_setopt($ch, CURLOPT_POST, True);
curl_setopt($ch, CURLOPT_VERBOSE, 1); // remove this if your not debugging
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate'); // please compress data
curl_setopt($ch, CURLOPT_USERAGENT, "gzip, My php curl client");
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,True);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec ($ch);
And get fine result with something like :
stdClass Object
(
[scan_id] => ffd8f48291484e1373573bfedf591cdf38565fcc9fc89a4a1d0f16a98da4d4ec-1573916013
[sha1] => d8cc708a1760020e00e1da0e83dc1f7b25e5a5ab
[resource] => ffd8f48291484e1373573bfedf591cdf38565fcc9fc89a4a1d0f16a98da4d4ec
[response_code] => 1
[sha256] => ffd8f48291484e1373573bfedf591cdf38565fcc9fc89a4a1d0f16a98da4d4ec
[permalink] => https://www.virustotal.com/file/ffd8f48291484e1373573bfedf591cdf38565fcc9fc89a4a1d0f16a98da4d4ec/analysis/1573916013/
[md5] => 7ae6fa4e9595a6e9d7987b4cd66f5b7f
[verbose_msg] => Scan request successfully queued, come back later for the report
)
Why do I set file wrong and have good result ?
Related
Is there a way to get the size of a remote file https://drive.google.com/uc?export=download&id=54fs54dg45f1f112f2 before downloading the file?
You could make a curl request to get sizeBytes.
<?php
$id = '0ByzJffaEk18uN2ZLeGlIRGVOaDJmWS1WU1RUN3d***';
$ch = curl_init('https://drive.google.com/uc?id='.$id.'&export=download');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, []);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$result = curl_exec($ch);
$object = json_decode(str_replace(')]}\'', '', $result));
print_r($object);
Result:
stdClass Object
(
[disposition] => SCAN_CLEAN
[downloadUrl] => https://doc-08-8o-docs.googleusercontent.com/docs/...
[fileName] => filename.sh
[scanResult] => OK
[sizeBytes] => 4936
)
I am trying to send attachment using curl through mailgun but its sending email with out attachment.(I am receiving email with only html part but no attachments.)
Here is my code
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, 'api:'.$api_key);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_URL, 'https://api.mailgun.net/v3/'.$domain.'/messages');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
$result = curl_exec($ch);
curl_close($ch);
return $result;
$postFields is array with following value.
Array
(
[from] => ***
[to] => ***
[subject] => ***
[html] => ***
[attachment] => Array
(
[0] => /home/***/n.jpg
[1] => /home/***/n2.jpg
)
)
I am polling live prices from the Skyscanner API. Although I receive the session_key and although I am immediately polling the results I am getting a 410 (Gone) response header with an empty body. It used to work fine from my localhost environment but not on my live server anymore.
Has anybody experienced this before and can maybe give me a hint what the issue could be?
$url_api = "http://partners.api.skyscanner.net/apiservices/pricing/v1.0/";
$api_key = "XXX"; // Not shown here
$data = array('apiKey' => $api_key, 'country' => 'DE', 'currency' => 'EUR',
'locale' => 'de-DE', 'originplace' => 'HAM', 'destinationplace' => 'AMS', 'cabinclass' => 'economy', 'outbounddate' => '2017-01-27',
'inbounddate' => '2017-01-30' , 'locationschema' => 'Iata', 'groupPricing' => true);
$httpdata = http_build_query($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_api);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $httpdata);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Accept: application/json'));
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
$response = curl_exec($ch);
curl_close($ch);
$headers = get_headers_from_curl_response($response);
$url = $headers['Location']."?apiKey=".$api_key."&stops=0";
echo $url;
return;
I am trying to create ad account in Facebook business manager via Facebook marketing and graph API using following code.
$attachment = array('access_token' => $this->accessToken,
'name' => $associative_arr['name'],
'currency' => $associative_arr['currency'],
'timezone_id' => $associative_arr['timezone_id'],
'end_advertiser' => $this->mybusinessId,
'media_agency' => 'NONE',
'partner' => 'NONE',
'access_type' => 'OWNER',
'permitted_roles' => 'ADMIN'
//'user_role' => '1001'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$this->apiVersion.'/'.$this->mybusinessId.'/adaccount');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //to suppress the curl output
$result = curl_exec($ch);
$dcde = json_decode($result);
curl_close ($ch);
It successfully creates ad account but does not add me as a user in people with administrative access.
Can anyone give me suggestion what can be the reason?
Once the ad account is created, you'll need to make another call which will add the user with the required permissions.
$attachment = array(
'access_token' => $this->accessToken,
'business' => '<business_id>',
'user' => '<user_id>',
'role' => 'ADMIN'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$this->apiVersion.'/act_<AD_ACCOUNT_ID>/userpermissions');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //to suppress the curl output
$result = curl_exec($ch);
$dcde = json_decode($result);
curl_close ($ch);
How can I upload a file with PHP curl, using HTTP PUT instead of POST?
Use case
Assuming the following sample data...
$data = [
'foo' = bar;
'image_file' = curl_file_create('C:\sample.jpg','image/jpg','receipt.jpg')
];
I can post and upload the sample data above with the following curl options...
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
This results in the following data on the receiving end of the post...
Array
(
[foo] => 'bar'
[image_file] => Array
(
[name] => sample.jpg
[type] => image/jpg
[tmp_name] => C:\tmp\php8934.tmp
[error] => 0
[size] => 351836
)
)
Now, I'd like to do the same thing using HTTP PUT.
Attempt 1
If change to an http put using the following option...
//curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
...nothing is posted.
Attempt 2
If I also change the postfields option to...
//curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
The post works, but the upload doesn't. Here's the result...
Array
(
[foo] => 'bar'
[image_file] => Array
(
[name] => C:\sample.jpg
[mime] => image/jpg
[postname] => sample.jpg
)
)
Conclusion
I see no way of uploading files using HTTP PUT. Can it be done?
$image = fopen($file_path, "rb");
$curl = curl_init();
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_PUT, 1);
curl_setopt($curl, CURLOPT_INFILE, $image);
curl_setopt($curl, CURLOPT_INFILESIZE, filesize($file_path));
$result = curl_exec($curl);
curl_close($curl);
It can be done using code below:
#Initiate cURL object
$curl = curl_init();
#Set your URL
curl_setopt($curl, CURLOPT_URL, 'https://local.simbiat.ru');
#Indicate, that you plan to upload a file
curl_setopt($curl, CURLOPT_UPLOAD, true);
#Indicate your protocol
curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
#Set flags for transfer
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1);
#Disable header (optional)
curl_setopt($curl, CURLOPT_HEADER, false);
#Set HTTP method to PUT
curl_setopt($curl, CURLOPT_PUT, 1);
#Indicate the file you want to upload
curl_setopt($curl, CURLOPT_INFILE, fopen('path_to_file', 'rb'));
#Indicate the size of the file (it does not look like this is mandatory, though)
curl_setopt($curl, CURLOPT_INFILESIZE, filesize('path_to_file'));
#Only use below option on TEST environment if you have a self-signed certificate!!! On production this can cause security issues
#curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
#Execute
curl_exec($curl);