Created
December 20, 2016 08:51
-
-
Save vgrish/9dd812c11463e75d4653c5f09362f111 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$corePath = $modx->getOption('userfiles_core_path', null, | |
$modx->getOption('core_path', null, MODX_CORE_PATH) . 'components/userfiles/'); | |
/** @var UserFiles $UserFiles */ | |
$UserFiles = $modx->getService( | |
'userfiles', | |
'userfiles', | |
$corePath . 'model/userfiles/', | |
array( | |
'core_path' => $corePath | |
) | |
); | |
$data = array(); | |
$data['parent'] = 42; | |
$data['class'] = 'Ticket'; | |
$data['ctx'] = 'web'; | |
$data['action'] = 'file/upload'; | |
$data['list'] = 'default'; | |
$data['createdby'] = '1'; | |
$data['source'] = $modx->getOption('userfiles_source_default'); | |
$data['name'] = 'название'; | |
$data['anonym'] = 1; | |
$data['propkey'] = 1; | |
$data['_file_path'] = '/var/www/location/www/assets/userfiles/000/moddocument/5652/metallodetectory.jpg'; | |
$data['_file_name'] = 'metallodetectory.jpg'; | |
$data['properties'] = $modx->toJSON($data); | |
/*$curl = curl_init(); | |
$url = 'http://location.vgrish.ru/assets/components/userfiles/action.php'; | |
curl_setopt_array($curl, array( | |
CURLOPT_URL => $url, | |
CURLOPT_POST => true, | |
CURLOPT_POSTFIELDS => $data, | |
CURLOPT_RETURNTRANSFER => 1, | |
CURLOPT_TIMEOUT => 6 | |
)); | |
$result = curl_exec($curl); | |
curl_close($curl); | |
$result = $modx->fromJSON($result);*/ | |
$response = $modx->runProcessor('file/upload', | |
$data, | |
array('processors_path' => MODX_CORE_PATH.'components/userfiles/processors/mgr/') | |
); | |
if ($response->isError()) { | |
$modx->log(modX::LOG_LEVEL_ERROR, "Error: \n". print_r($response->getAllErrors(), 1)); | |
} | |
else { | |
$modx->log(modX::LOG_LEVEL_INFO, "Success \n". print_r($response->getObject(), 1)); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment