18 include_once (
"WHAT/Lib.FileMime.php");
34 private $host =
'localhost';
39 private $port = 51968;
48 if ($host !=
"") $this->host = $host;
49 if ($port > 0) $this->port = $port;
69 $address = gethostbyname($this->host);
70 $service_port = $this->port;
74 $timeout = floatval(
getParam(
"TE_TIMEOUT", 3));
75 $fp = @stream_socket_client(
"tcp://$address:$service_port", $errno, $errstr, $timeout);
78 $err = _(
"socket creation error") .
" : $errstr ($errno)\n";
80 "status" => self::error_connect
89 $out = trim(fgets($fp, 2048));
91 if (
$out ==
"Continue") {
92 $basename = str_replace(
'"',
'_', basename(
$filename));
95 $in =
"<TE name=\"$te_name\" fkey=\"$fkey\" fname=\"$basename\" size=\"$size\" mime=\"$mime\" callback=\"$callback\"/>\n";
96 #echo "Envoi du header $in ...";
98 $out = trim(fgets($fp));
100 if (preg_match(
"/status=[ ]*\"([^\"]*)\"/i",
$out, $match)) {
103 if ($status ==
'OK') {
108 while (!feof($handle)) {
109 $buffer = fread($handle, 2048);
110 $cout = fwrite($fp, $buffer, strlen($buffer));
118 $out = trim(fgets($fp));
119 if (preg_match(
"/status=[ ]*\"([^\"]*)\"/i",
$out, $match)) {
122 if (preg_match(
"/<response[^>]*>(.*)<\/response>/i",
$out, $match)) {
127 if ($status ==
"OK") {
128 if (preg_match(
"/ id=[ ]*\"([^\"]*)\"/i", $outmsg, $match)) {
131 if (preg_match(
"/status=[ ]*\"([^\"]*)\"/i", $outmsg, $match)) {
134 if (preg_match(
"/<comment>(.*)<\/comment>/i", $outmsg, $match)) {
143 $err = $outcode .
" [$outmsg]";
148 if (preg_match(
"/<comment>(.*)<\/comment>/i",
$out, $match)) {
150 "status" => self::error_noengine
154 $err = _(
"Error sending file");
156 "status" => self::error_sendfile
165 $err = _(
"empty file");
167 "status" => self::error_emptyfile
183 $address = gethostbyname($this->host);
184 $service_port = $this->port;
188 $fp = stream_socket_client(
"tcp://$address:$service_port", $errno, $errstr, 30);
191 $err = _(
"socket creation error") .
" : $errstr ($errno)\n";
200 $out = trim(fgets($fp, 2048));
202 if (
$out ==
"Continue") {
204 $in =
"<TASK id=\"$tid\" />\n";
208 $out = trim(fgets($fp));
209 if (preg_match(
"/status=[ ]*\"([^\"]*)\"/i",
$out, $match)) {
213 if ($status ==
"OK") {
215 if (preg_match(
"/<task[^>]*>(.*)<\/task>/i",
$out, $match)) {
218 if (preg_match_all(
"|<[^>]+>(.*)</([^>]+)>|U", $body, $reg, PREG_SET_ORDER)) {
220 foreach ($reg as $v) {
221 $info[$v[2]] = $v[1];
227 if (preg_match(
"/<response[^>]*>(.*)<\/response>/i",
$out, $match)) {
230 $err = $status .
" [$msg]";
268 $err = sprintf(
"cannot open file <%s> in write mode",
$filename);
272 $address = gethostbyname($this->host);
273 $service_port = $this->port;
277 $fp = stream_socket_client(
"tcp://$address:$service_port", $errno, $errstr, 30);
280 $err = _(
"socket creation error") .
" : $errstr ($errno)\n";
288 $out = trim(fgets($fp, 2048));
290 if (
$out ==
"Continue") {
292 $in =
"<task id=\"$tid\" />\n";
296 $out = trim(fgets($fp, 2048));
298 if (preg_match(
"/status=[ ]*\"([^\"]*)\"/i",
$out, $match)) {
301 if ($status ==
"OK") {
303 if (preg_match(
"/size=[ ]*\"([^\"]*)\"/i",
$out, $match)) {
316 $buf = fread($fp, $rsize);
320 $wb = fwrite($handle, $buf);
329 $out = trim(fgets($fp, 2048));
330 if (preg_match(
"/status=[ ]*\"([^\"]*)\"/i",
$out, $match)) {
333 if ($status !=
"OK") {
334 if (preg_match(
"/<response[^>]*>(.*)<\/response>/i",
$out, $match)) {
337 $err =
"$status:$msg";
342 if (preg_match(
"/<response[^>]*>(.*)<\/response>/i",
$out, $match)) {
345 $err =
"$status:$msg";
366 $address = gethostbyname($this->host);
367 $service_port = $this->port;
371 $fp = stream_socket_client(
"tcp://$address:$service_port", $errno, $errstr, 30);
374 $err = _(
"socket creation error") .
" : $errstr ($errno)\n";
383 $out = trim(fgets($fp, 2048));
385 if (
$out ==
"Continue") {
387 $in =
"<TASK id=\"$tid\" />\n";
391 $out = trim(fgets($fp));
392 if (preg_match(
"/status=[ ]*\"([^\"]*)\"/i",
$out, $match)) {
395 if ($status ==
"OK") {
397 if (preg_match(
"/<task[^>]*>(.*)<\/task>/i",
$out, $match)) {
400 if (preg_match_all(
"|<[^>]+>(.*)</([^>]+)>|U", $body, $reg, PREG_SET_ORDER)) {
402 foreach ($reg as $v) {
403 $info[$v[2]] = $v[1];
409 if (preg_match(
"/<response[^>]*>(.*)<\/response>/i",
$out, $match)) {
412 $err = $status .
" [$msg]";