Changes for page File transfer
Last modified by Sylvain Berfini on 2018/02/28 11:41
From version 2.1
edited by Sylvain Berfini
on 2017/02/21 14:48
on 2017/02/21 14:48
To version 3.1
edited by Sylvain Berfini
on 2017/02/21 14:51
on 2017/02/21 14:51
Change comment: There is no comment for this version
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -23,20 +23,45 @@ 23 23 along with this program. If not, see <http://www.gnu.org/licenses/>. 24 24 --> 25 25 26 -<file-info type="file"> 27 -<file-size>'.$_FILES['File'][size].'</file-size> 28 -<file-name>'.$_FILES['File'][name].'</file-name> 29 -<content-type>'.$_FILES['File'][type].'</content-type> 30 -<data url = "'.$http_url.'" until = "'.$until.'"/> 31 -</file-info> 32 -</file>'; 26 +date_default_timezone_set("UTC"); 27 +if (count($_FILES) != 0) { 28 + $uploaddir = dirname(__FILE__).'/tmp/'; 29 + $rcvname=$_FILES['File']['name']; 30 + $ext= strtolower(pathinfo($rcvname, PATHINFO_EXTENSION)); 31 + //$allowed_ext = array("jpg", "txt", "zip", "zlib", "gz"); 32 + //if (!in_array($ext, $allowed_ext)) $ext="jpg"; 33 + $tmpfile=$_FILES['File']['tmp_name']; 34 + if (strlen($tmpfile) <= 0) { 35 + custom_log(upload_error_message($_FILES['File']['error'])); 36 + } 33 33 38 + custom_log('Uploaded '.$rcvname.' to '.$tmpfile); 39 + //$uploadfile = $uploaddir.time().md5_file($tmpfile).".".$ext; 40 + $uploadfile = $uploaddir.uniqid()."_".bin2hex(openssl_random_pseudo_bytes(10)).".$ext"; 41 + 42 + if (move_uploaded_file($tmpfile, $uploadfile)) { 43 + custom_log('Moved to '.$uploadfile); 44 + $ipport = $_SERVER['HTTP_HOST']; 45 + $prefix= (isset($_SERVER["HTTPS"]) && strtolower($_SERVER["HTTPS"])=="on")?"https":"http"; 46 + $start= $prefix."://".$ipport.dirname($_SERVER['REQUEST_URI']); 47 + $http_url = $start."/tmp/".basename($uploadfile); 48 + 49 + // validity time is one week ahead from now 50 + $until = date("Y-m-d\TH:i:s\Z",time()+7*24*60*60); 51 + echo '<file xmlns="urn:gsma:params:xml:ns:rcs:rcs:fthttp"> 52 + <file-info type="file"> 53 + <file-size>'.$_FILES['File']['size'].'</file-size> 54 + <file-name>'.$_FILES['File']['name'].'</file-name> 55 + <content-type>'.$_FILES['File']['type'].'</content-type> 56 + <data url = "'.$http_url.'" until = "'.$until.'"/> 57 + </file-info> 58 + </file>'; 34 34 } 35 35 } 36 36 if ((count($_POST) == 0) && (count($_FILES) == 0)) { 37 37 if (!function_exists('http_response_code')) { 38 38 $protocol = (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'); 39 - 64 + header($protocol . ' 204 No Content'); 40 40 $GLOBALS['http_response_code'] = 204; 41 41 } else { 42 42 http_response_code(204);