<?php require 'gview_svg.inc'; $upload_dir = "uploads/"; $fh = opendir($upload_dir); if (is_array($_FILES) && sizeof($_FILES) > 0) { $target_path = $upload_dir . basename($_FILES['uploadedfile']['name']); if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path) && chmod($target_path, 0775)) { if (gcode_to_svg($target_path)) { header("Location: /gview/"); } echo "The file " . basename($_FILES['uploadedfile']['name']) . " has been uploaded"; } else { echo "There was an error uploading the file, please try again!"; } } ?> <center> <?php while ($file = readdir($fh)) { if (filetype($upload_dir . "/" . $file) == "dir" && $file != "." && $file != "..") { ?> <a href=view.php?file=<?php echo $file; ?> ><?php echo $file; ?> </a><br> <?php }
#!/usr/bin/php <?php $startDir = dirname($argv[0]); gcode_to_svg($argv[1], $startDir); function gcode_to_svg($inFile, $startDir) { if (($fh = fopen($inFile, 'r')) === FALSE) { exit; } $cur['X'] = ""; $cur['Y'] = ""; $last['X'] = ""; $last['Y'] = ""; $last['Z'] = ""; $cur['Z'] = ""; $min['X'] = 0; $min['Y'] = 0; $min['Z'] = ""; $resolution = 3; $layers = array(); while ($fh !== FALSE && !feof($fh)) { $buf = fgets($fh, 1024); $bufsplit = explode(" ", $buf); if (is_array($bufsplit) && sizeof($bufsplit) > 0 && preg_match("/^G[1|0]\$/", $bufsplit[0])) { for ($i = 1; $i < sizeof($bufsplit); $i++) { $curcode = substr($bufsplit[$i], 0, 1); $val = substr($bufsplit[$i], 1, strlen($bufsplit[$i])); $cur[$curcode] = $val; } $displayLine = true; if ($cur['Z'] != $last['Z']) {