title: PHP convert Image file to binary string
body: <p>I want to convert an image I retrieve from a form to binary string so that I can insert it into a sqlplus table. I've looked around at how to do this conversion and I found that most solutions have this:</p>
  
  <p><strong>example table:</strong></p>
  
  <pre><code>CREATE TABLE images (
      image_id int,
      image blob 
      PRIMARY KEY (image_id));
  </code></pre>
  
  <p><strong>Form:</strong></p>
  
  <pre><code>&lt;form method="post" enctype="multipart/form-data" action="./Upload/UploadImage.php"&gt;
  &lt;label for="file"&gt;Filename:&lt;/label&gt;
  &lt;input type="file" name="file" id="file"&gt;&lt;span style="color: #FF0000;"&gt;*&lt;/span&gt;&lt;br/&gt;
  &lt;input type="submit" name="uploadImage" value="Upload Image"&gt;&lt;/form&gt;
  </code></pre>
  
  <p><strong>Proposed Conversion Solution:</strong></p>
  
  <pre><code>&lt;?php
      $data = file_get_contents($_FILES["file"]["tmp_name"]);
      $encoded_data = base64_encode($data);
      //echo the data to check it's there
      echo "Encoded Data: " . $encoded_data;
  ?&gt;
  </code></pre>
  
  <p>If I echo <code>$data</code> I get a jumbled string, but if i echo <code>$encoded_data</code> I just get: <code>Encoded Data:</code> then nothing. </p>
  
  <p>I want to be able to insert this binary data into my db using </p>
  
  <pre><code>$sql = 'INSERT INTO images VALUES (1, \'' . $encoded_data . '\')';
  </code></pre>
  
  <p><em>(I know this is just the sql string - the execution of the statement is not something I felt I needed to include).</em></p>
  
  <p><strong>UPDATE:</strong> I realized I had a type in my <code>$encoded_data = base64_encode($data);</code> line so that works now but the sql throws a string literal too long error.</p>