如何配置linphone图片分享服务器到我们自己的服务器

How to config linphone image sharing server to our own server

我最近在玩linphone,我成功地将它与我自己的服务器集成,用于通话和短信,但是我正在尝试配置发送图像,但它根本不起作用。我在自己的服务器上获取了用于文件上传的 .php 文件,我将共享图像服务器从 linphone 指向它,但它没有向服务器发送任何参数。

这里的例子http://osdir.com/ml/linphone-developers-sip-voip/2013-08/msg00003.html

<?php

function getExtension($str)
{
    $i = explode('.', $str);
    return strtolower(end($i));
}
if ($_FILES["userfile"]["error"] > 0)
  {
      return;
  }
else
  {
  $size = ($_FILES["userfile"]["size"] / 1024);
  if($size > 1000)
  {
     return;
  }
  $locdir = dirname(__FILE__);
  $globdir = "http://192.168.91.101/userdata";

  $uploaddir = '/images/' . date('Y-m-d') . '/';
  if (!is_dir($uploaddir)) {
    mkdir($uploaddir, 0777);         
  }
  $uploadfile  = $uploaddir . uniqid() . '.' . getExtension($_FILES["userfile"]["name"]);

  if (move_uploaded_file($_FILES['userfile']['tmp_name'], $locdir . $uploadfile)) 
  {
    echo $globdir . $uploadfile;
  }
}
?> 

好的,这是原始 PHP 文件 - https://wiki.linphone.org/wiki/index.php/Liblinphone:file_transfer

<?php
date_default_timezone_set("UTC");
if (count($_FILES) != 0) {
    $uploaddir = dirname(__FILE__).'/tmp/';
    $rcvname=$_FILES['File']['name'];
    //$ext= strtolower(pathinfo($rcvname, PATHINFO_EXTENSION));
    //$allowed_ext = array("jpg", "txt", "zip", "zlib", "gz");
    if (!in_array($ext, $allowed_ext)) $ext="jpg";
    $tmpfile=$_FILES['File']['tmp_name'];

    error_log('Uploaded '.$rcvname.' to '.$tmpfile."\n", 3, "/var/log/trace_file_sharing.log");
    //$uploadfile = $uploaddir.time().md5_file($tmpfile).".".$ext;
    $uploadfile = $uploaddir.uniqid()."_".bin2hex(openssl_random_pseudo_bytes(10)).".$ext";

    if (move_uploaded_file($tmpfile, $uploadfile)) {
            error_log('Moved to '.$uploadfile."\n", 3, "/var/log/trace_file_sharing.log");
            $ipport = $_SERVER['HTTP_HOST'];
            $prefix= (isset($_SERVER["HTTPS"]) && strtolower($_SERVER["HTTPS"])=="on")?"https":"http";
            $start= $prefix."://".$ipport.dirname($_SERVER['REQUEST_URI']);
            $http_url = $start."/tmp/".basename($uploadfile);

        // validity time is one week ahead from now
        $until = date("Y-m-d\TH:i:s\Z",time()+7*24*60*60);
        echo '<?xml version="1.0" encoding="UTF-8"?><file xmlns="urn:gsma:params:xml:ns:rcs:rcs:fthttp">
<file-info type="file">
<file-size>'.$_FILES['File'][size].'</file-size>
<file-name>'.$_FILES['File'][name].'</file-name>
<content-type>'.$_FILES['File'][type].'</content-type>
<data url = "'.$http_url.'" until = "'.$until.'"/>
</file-info>
</file>';

    }
}
if ((count($_POST) == 0) && (count($_FILES) == 0)) {
    if (!function_exists('http_response_code')) {
        $protocol = (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0');
                header($protocol . ' 204 No Content');
        $GLOBALS['http_response_code'] = 204;
    } else {
        http_response_code(204);
    }
}
?>

只需复制粘贴即可。

它的 send/answer 这个 xml 文档给另一个使用 linphone 的用户。

<?xml version="1.0" encoding="UTF-8"?><file xmlns="urn:gsma:params:xml:ns:rcs:rcs:fthttp">
<file-info type="file">
<file-size>64475</file-size>
<file-name>25756.jpg</file-name>
<content-type>image/jpeg</content-type>
<data url = "http://xxx.xxx.xxx./path/file.jpg" until = "2015-11-18T20:13:00Z"/>
</file-info>
</file>

如果你想让它与 Asterix 兼容,你需要像 xml 文档那样实现正确的答案,或者只发送 echo "Photo'.$http_url.'"(这与 Jitsi 一起工作)..