shamuraq Posted December 7, 2009 Share Posted December 7, 2009 hi all, I have seen and sampled many dynamically generated SVG via PHP. What i need to do is 1)save the output as .svg instead of having the svg parsed image still in .php document. 2)save the output .svg to a specific folder in the server. Any suggestions/ideas? Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted December 7, 2009 Share Posted December 7, 2009 Just use fopen, fwrite and fclose or file_put_contents. Quote Link to comment Share on other sites More sharing options...
shamuraq Posted December 7, 2009 Author Share Posted December 7, 2009 Hi Daniel0, i'm still trying to piece up your reply but am still stuck... lets just say i have the code below, how do u get them to save the "parsed" svg which is still in .php into a .svg and saved into a certain folder in the server? <?php header("Content-type: image/svg+xml"); $output ="<?xml version=\"1.0\" standalone=\"no\"?>"; $output .="<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"; $output .= "<svg width=\"750\" height=\"710\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">"; //class style sheet $output .= "<style type=\"text/css\"> <![CDATA[ .Border { fill:none; stroke:#a4a4a4; stroke-width:1; stroke-dasharray: 5, 3, 9, 2; } .Connect { fill:#505050; stroke:#888888; stroke-width:2; opacity:0.7 } .Connect1 { fill:#FFFFFF stroke:midgrey; stroke-width:1; opacity:0.7 } .Connect2 { fill:#333333; stroke:#777777; stroke-width:1; opacity:0.7 } .SamplePath { fill:none; stroke:#CCCCCC; stroke-width:1 } .EndPoint { fill:none; stroke:#888888; stroke-width:2 } .CtlPoint { fill:#888888; stroke:none } .AutoCtlPoint { fill:none; stroke:blue; stroke-width:4 } .Label {font-family: Arial } ]]> </style>"; $pattern = array(); for($i = 0; $i<$color1; $i++){ $pattern[$i] = '#FFFFFF'; } for($i = $color1; $i<$boxes; $i++){ $pattern[$i] = '#666666'; } shuffle($pattern); //print_r($pattern); for($i = 0; $i < $boxes; $i++){ $x = $x + 20; $a1 = $pattern[$i]; $output .= "<rect style=\"fill:$a1;stroke: #777777\" x=\"$x\" y=\"$y\" width=\"$w\" height=\"$h\">"; $output .= "</rect>"; } $output .= "</svg>\n"; print $output; ?> Quote Link to comment Share on other sites More sharing options...
simshaun Posted December 7, 2009 Share Posted December 7, 2009 I don't see why you would be stuck. Take $output and use it with file_put_contents. It doesn't get much easier than that. file_put_contents('/path/to/folder/on/server/someFile.svg', $output); Just make sure the folder you are writing to has the proper permissions, and you may even want to chmod the file. Otherwise you should be good to go. Quote Link to comment Share on other sites More sharing options...
shamuraq Posted December 15, 2009 Author Share Posted December 15, 2009 Lolxxx... sorry with the late reply... Problem with internet bill settlement... I'll give it a try... Thanx again... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.