protected function ContextUploader::uploadAsset in TMGMT Translator Smartling 8
Parameters
string $url:
string $resourceId:
1 call to ContextUploader::uploadAsset()
- ContextUploader::upload in src/
Context/ ContextUploader.php
File
- src/
Context/ ContextUploader.php, line 160
Class
Namespace
Drupal\tmgmt_smartling\ContextCode
protected function uploadAsset($url, $resourceId, $proj_settings) {
$orgId = $proj_settings['orgID'];
$resource['url'] = $url;
$resource['resource'] = @file_get_contents($url);
if ($resource['resource'] !== FALSE) {
$contet_type = get_headers($resource['url'], 1)["Content-Type"];
//$resource['resource'] = @fopen($resource['url'], 'r');//$content;
$resource['orgId'] = $orgId;
$resource['resourceId'] = $resourceId;
$res_fil = basename($resource['url']);
$res_fil = strpos($res_fil, '?') === FALSE ? $res_fil : strstr($res_fil, '?', TRUE);
if (empty($res_fil)) {
$this->logger
->warning('Asset "@url" can not be uploaded. Bad filename.', [
'@url' => $resource['url'],
]);
return;
}
$res = $this
->getApi($proj_settings, TRUE)
->putResource($resource, [
'resource' => [
'name' => $res_fil,
'content_type' => $contet_type,
],
]);
}
else {
$this->logger
->warning('File "@url" can not be downloaded. Probably it does not exist or server returned 403 status code for a given resource.', [
'@url' => $resource['url'],
]);
}
}