I am storing a converted base64 encoded string as an image file. I have to get the file as a string. 

Currently I get the string via POST and I am worried about someone posting something that they might be able to use to compromise the sever. My question is how to make sure this is as secure as it can be.

This is how it works at the moment (summarised):

```
$encodedString = $_POST['image'];
// Strip the crud from the front of the string [1]
$encodedString = substr($encodedString,strpos($encodedString,",")+1);
// Cleanup File [2]
$encodedString = str_replace(' ','+',$encodedString);
// Decode string
$decoded = base64_decode($encodedString);
// Save File
file_put_contents(uniqid().'.png',$decoded);

```

What should I do next to ensure that someone doesn't/hasn't inject(ed) some malicious code into the post variable? 

Or is there a better way than POST?

References:

1. [Convert Base64 string to an image file?](https://stackoverflow.com/questions/15153776/convert-base64-string-to-an-image-file)
2. [PHP Data-URI to file](https://stackoverflow.com/questions/6735414/php-data-uri-to-file/6735480#6735480)