Tuesday, November 29, 2011

SVG Edit : Saving files to server


SVG-edit is a fast, web-based, Javascript-driven SVG editor that works in any modern browser. To learn more about SVG-edit, click here . By default, while clicking on the save link given in the menu, the image is opening in new window and user has to manually save the image to user's machine. SVG-edit (version 2.5.1) has given an extension to download the files to user's machine.

To download the file

Open svg-editor.js

In curConfig object, to the extensions array add 'ext-server_opensave.js' to the end. Make sure that ext-server_opensave.js , fileopen.php and filesave.php exist in the svg/extensions directory

To save the file to server

Do the above steps.

Open the extensions/filesave.php and comment out below code

header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=" . $file);
header("Content-Type: " . $mime);
header("Content-Transfer-Encoding: binary");
echo $contents;

And add the following code at the end

define('DIR_PATH', 'path to the directory with trailing slash');
$fp = fopen(DIR_PATH . $file, 'w+');
fwrite($fp, $contents);
fclose($fp);


Give proper directory path to DIR_PATH constant and give necessary permission to the folder

No comments: