How to config linphone image sharing server to our own server

2.3k views Asked by At

I recently have played around with linphone, and I successfully integrate it with my own server for call, and text message, However I am trying to config the sending image and it does not work at all. I get the .php file for file upload on own server and I point the sharing image server from linphone to it but it does not send any parameters to the server.

2

There are 2 answers

1
Daniel Valeriev On BEST ANSWER

Ok, here is original PHP file - 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);
    }
}
?>

just copy paste, its work.

its send/answer this xml document to another user that use 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>

If you want to make it compatible with Asterix you need to implement the correct answer like xml document or just send echo "Photo'.$http_url.'" (this work with Jitsi)..

1
Daniel Valeriev On

Example from here 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;
  }
}
?>