public function fileUpload file if array_key_exists path file file_exi

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
public function fileUpload($file) {
if(!array_key_exists('path', $file) || !file_exists($file['path']))
$this->toLog('Неверный путь к файлу!', self::ERROR);
if($this->action === null) {
$res = $this->request('/files/?r=main/upload');
preg_match('/action="(.*?)"/', $res, $action);
$this->action = htmlspecialchars_decode($action[1]);
}
$res = $this->request($this->action, array(
'myFile' => '@' . $file['path'] . (array_key_exists('name', $file) ? ';filename=' . $file['name'] : ''),
'dir' => array_key_exists('dir', $file) ? (String) $file['dir'] : '0',
'file_descr' => array_key_exists('descr', $file) ? $file['descr'] : '',
'compat' => array_key_exists('compat', $file) ? $file['compat'] : '',
'adult' => array_key_exists('adult', $file) ? (String) $file['adult'] : '0'
));
preg_match('/read=(\d+)/i', $res, $read);
$read = $read[1];
echo $res;
echo '<hr>';
//return $read;
}