вторник, 7 августа 2012 г.

Silverlight Online Plotter


Today I'd like to tell you about one of my old projects Silverlight Online Plotter. This is a tool that allows you to create function graphs right in browser, compare them, export and import. 

Live demo is not allow to export because I have not implemented web service that saves data. In silverlight 3.0 there is no way to create save dialog, so I exported data with http-handler. I created web request to web-service that saved data to a file and set session variable with filename. Than I made browser redirect to http-handler that returned this file.

There is code of web-service in PHP:

<?php

session_start();

if ($_GET['file']) {
$filename = $_SERVER['DOCUMENT_ROOT'].'/files/'.$_GET['file']; 
$f = fopen($filename, 'r');
if (!$f) { 
header('HTTP/1.0 404 Not Found');
exit();
}
header('Content-type: application/xplt');
header('Content-Disposition: attachment; filename="plots.xplt"');
header('Content-Length: '.filesize($filename));
echo fread($f, filesize($filename));
fclose($f);
@unlink($filename);
exit();

if ($_POST['data']) {
$f = fopen($_SERVER['DOCUMENT_ROOT'].'/files/'.session_id().'.xml', 'w');
fwrite($f, stripslashes($_POST['data']));
fclose($f);
header('Content-type: text/xml');
echo '<?xml version="1.0" encoding="utf-8" ?><data status="0" file="'.session_id().'.xml" />';
exit();
}

header('Content-type: text/xml');
echo '<?xml version="1.0" encoding="utf-8" ?><data status="1" />';

?>

Комментариев нет:

Отправить комментарий