PHP won’t post image data

Okay so I’m working on a program that takes canvas data, takes a screenshot, adds in in a text box, and posts it to htdocs/creations/random number.xml. It posts some subbmited data; but not the model tag.

The model tag gets the JSC3D (I know no one here has ever heard of that; that has nothing to do with the problem) data from the text box I talked about and adds it should add it as <model>image data</model>. But instead it outputs the model tag as </model>. No opening tag or data; just </model>.

Here’s my PHP code:

<?php
$errors = array();

if(isset($_POST['save'])){

    $canvas = $_POST['img_text'];

    $username = $_SESSION['username'];

    $model_id = rand(1, 10000);

    $model_name = $_POST['name'];

    $model_description = $_POST['description'];

    if(file_exists('../creations/' . $model_id . '.xml')){
        $errors[] = 'Random model ID already exists. Please try saving again';
        }

    if($model_name == '') {
        $errors[] = 'Model name is blank';
    }

    if($model_description == ''){
        $errors[] = 'Description is blank';
        }

        if(count($errors) == 0){
            $xml = new SimpleXMLElement ('<creation></creation>');

            $xml->addChild('model', $canvas);

            $xml->addChild('id', $model_id);

            $xml->addChild('name', $model_name);

            $xml->addChild('description', $model_description);

            $xml->asXml('../creations/' . $model_id . '.xml');

            header('Location: index.php');
        }
            
}
?>
<!DOCTYPE HTML">
<HTML>
 <HEAD>
  <TITLE> JSC3D - test </TITLE>
  <!--[if lt IE 9]><script type="text/javascript" src="js/flashcanvas.js"></script><![endif]-->
  <link rel="stylesheet" type="text/css" href="style.css">
 </HEAD>

 <BODY onload="init()">

     <div class="action_buttons">
        <b>Actions:</b>
        <input type="button" value="File" onClick="alert('Error loading save menu')" />
        <input type="button" value="Help" onClick="alert('Error loading help menu')" />
        <input type="button" value="Rotate down" onClick="viewer.rotate(-10,0,0);viewer.update();" />
        <input type="button" value="Rotate up" onClick="viewer.rotate(10,0,0);viewer.update();" />
        <input type="button" value="Rotate left" onClick="viewer.rotate(0,-10,0);viewer.update();" />
        <input type="button" value="Rotate right" onClick="viewer.rotate(10,0,0);viewer.update();" />
        <input type="button" value="Zoom in" onClick="viewer.zoom(0,10,0);viewer.update();" />
        <input type="button" value="Zoom out" onClick="viewer.zoom(0,-10,0);viewer.update();" />
        <input type="button" value="Reset viewer" onClick="viewer.resetScene();viewer.update();" />
     </div>

    <div class="mode_buttons">
        <b>Mode:</b>
        <input type="radio" name="operate" value="rotate" onclick="viewer.setMouseUsage(&#39;rotate&#39;);" checked="true">Rotate
        <input type="radio" name="operate" value="zoom" onclick="viewer.setMouseUsage(&#39;zoom&#39;);">Zoom
        <input type="radio" name="operate" value="pan" onclick="viewer.setMouseUsage(&#39;pan&#39;);">Pan
    </div>
    
    <div class="blocks">
        <b>Scene:</b>
        <select id="model_list">
        <option>base.stl</option>
        <option>jsc_logo.obj</option>
        <option>blocks.obj</option>
        <option>minifig.obj</option>
        </select>
        <input type="button" id="load" value="Load model" onClick="loadModel();" />
        <select id="render_mode_list">
        <option>render as flat</option>
        <option>render as smooth</option>
        <option>render as wireframe</option>
        <option>render as points</option>
        <option>render with environment</option>
        </select>
        <input type="button" id="change" value="Change render mode" onClick="setRenderMode();" />
     </div>

     <form method="post" action="">
            <?php
            if(count($errors) > 0) {
                echo '<ul>';
                foreach($errors as $e){
                    echo '<li>' . $e . '</li>';
                }
                echo '<ul>';
            }
            ?>

            <br/>

            <div class="save">

                <b>Save:</b>
                <input type="text" value="Name" name="name" />
                <input type="text" value="Description" name="description" />
                <br />
                <input type="submit" value="Save model" name="save" />

                <div class="screenshot"><input type="button" id="screenshot" value="Take screenshot" onClick="takeScreenshot();" /></div>
                <br /><center><div id="sc"></div></center>

            </div>
        </form>

    <div id="canvas-head" style="width:640px; margin:auto; position:relative; font-size: 9pt; color: #777777;">
        <canvas id="cv" style="border: 1px solid;" width="640px" height="480px" ></canvas>
    <div>
        
     <canvas id="tex" style="border:1px solid;" width="1" height="1"></canvas>
    </div>
    
    */ ie or not /*
    <!--[if !IE]><!-->
     <script type="text/javascript" src="jsc3d.js"></script>
     <script type="text/javascript" src="jquery.js"></script>
    <!--<![endif]-->
    <!--[if IE]>
     <script type="text/javascript" src="ie.js"></script>
     <script type="text/javascript">
      JSC3D.Texture.cv = document.getElementById('tex');
     </script>
    <![endif]-->
    <script>
    */ JS3CD stuffz /*

   
   function takeScreenshot() {
        var canvas = document.getElementById("cv");
        var imgData    = canvas.toDataURL("image/png");
        document.getElementById("sc").innerHTML += '<img src="'+imgData+'" id="image">';
        $(image).width(240);

        document.getElementById("sc").innerHTML += '<input type="text" value="'+imgData+'" id="img_text">';
        $(image).width(240);
        
    }

  </script>
 </BODY>
</HTML>