public function multiThreadUpload if this- action null res this- reque

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
public function multiThreadUpload() {
if($this->action === null) {
$res = $this->request('/files/?r=main/upload');
preg_match('/action="(.*?)"/', $res, $action);
$this->action = htmlspecialchars_decode($action[1]);
}
$multi = curl_multi_init();
foreach($this->files as $key => $file) {
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_HEADER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERAGENT => self::USERAGENT,
CURLOPT_COOKIE => 'sid=' . $this->account['sid'],
CURLOPT_URL => $this->action,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => 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'
)
));
curl_multi_add_handle($multi, $ch);
}
$active = null;
do {
$mrc = curl_multi_exec($multi, $active);
} while($mrc == CURLM_CALL_MULTI_PERFORM);
while ($active && ($mrc == CURLM_OK)) {
if (curl_multi_select($multi) != -1) {
do {
$mrc = curl_multi_exec($multi, $active);
$info = curl_multi_info_read($multi);
if ($info['msg'] == CURLMSG_DONE) {
$ch = $info['handle'];
echo curl_multi_getcontent($ch) . '<hr/>';
curl_multi_remove_handle($multi, $ch);
curl_close($ch);
}
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
}
curl_multi_close($multi);
}