A beginner question on passthru() function in PHP
        Posted  
        
            by 
                Robert
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Robert
        
        
        
        Published on 2011-01-03T18:52:00Z
        Indexed on 
            2011/01/03
            18:54 UTC
        
        
        Read the original article
        Hit count: 274
        
Hi all,
I've used the following code to do an XSLT translation in PHP and save the result SVG file into a sub folder:
$command = $java . $saxon . $target2 . ' ' . $xsl2.' '.$param;
ob_start();
passthru($command, $result);
$content_grabbed=ob_get_contents();
ob_end_clean();
$info = pathinfo($_FILES['file']['name']);
$file_name= basename($_FILES['file']['name'],'.'.$info['extension']);
$myFile = "images/convert/".$file_name."_".$_POST["mydropdown"].".svg";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $content_grabbed);
fclose($fh);
It does a very simple SVG to SVG transformation, and created the resulting SVG file. the $command is just a simple java -jar saxon.jar input.xml stylesheet java command. The current situation is ,the file gets created perfectly, however, the error gets shown in browser, probably because I inserted the "ob_start" before passthru() command.
I am thinking of making use of an argument that comes with the saxon.jar, that is "-o output_file_name". Because the final purpose is not to display the resulting SVG to the browser, but instead creating an SVG file ,and provide the link to the user for downloading.
Are there any better ways to handle this problem, I am still thinking about how to get rid of the result that gets shown in the browser that is sent by the "passthru()". Thanks in advance for suggestions!
© Stack Overflow or respective owner