title: PHP/Txt - How to save into session/load from session
body: <p>This is quite a long-winded question as im completely lost!</p>
  
  <p>The concept: User inputs a text file they wish to write to, upon submitting they are sent to a page where users can create shapes and submit them to the text file, this data is then used to work out the shapes area, colour that was selected etc... </p>
  
  <p>Issue is how do i write to a text file that is in the session?</p>
  
  <p>This is what i have on the home page:</p>
  
  <pre><code>&lt;?php
  
  // This line starts the session
  
  session_start();
  
  //The below calls the file
  
  $txtFile = $_POST['submittedTxtFile']; 
  $_SESSION['submittedTxtFile']= $txtFile;
  $file = fopen($txtFile, "r") or exit("That file does not exist");
  
  include_once 'classShapeCollection.php';
  
  //Creates the shapecollection
  $shapes = new ShapeCollection();
  
  //These lines get the called file, unserialize the $shapes and serialize them again before entering them into the session.
  
  $buffer = fgets($file);
  
  //Checking if there are any contents in the file
  
  if($buffer)
  
      {
      $shapes = unserialize($buffer); //unserialize takes Text and turns it into an object
      $_SESSION['serial']= serialize($shapes); //Serialize takes the objects and converts them into Text
      }
      else //if there is nothing in the file, the session serialises the new ShapeCollection
      {
      $_SESSION['serial']= serialize($shapes);
      }
  
  // Closes the called file
  fclose($file);
  ?&gt;
  </code></pre>