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: