I'm uploading files to my PHP webservice by encoding them to Base64 and sending them via Json.
I'm decoding the data on the server using this code: $file_content = base64_decode($file,true);
Now I want to extract file name and extension from the $file_content
variable.
How can I do that?
UPDATE: here is the code I used to decode the file:
include '../conn.php';
include '../functions.php';
$entityBody = file_get_contents('php://input');
$decodedJson = json_decode($entityBody);
$user_email = $decodedJson->{'email'};
$user_token = $decodedJson->{'token'};
$file = $decodedJson->{'file'}; //This is the encoded content of the file from JSON
$file_content = base64_decode($file,true);
if(!checkStudentAuthorizationOrHigher($user_email,$user_token,$conn))
{
die();
}
//now I want to get $file_content type (extension or MIME type) and
//file name from the $file_content
//I tried the below code but it only gets file path as input parameter and doesn't work this way
echo mime_content_type($file_content);
Only the file content is given to my PHP webservice through JSON (file name or extension is not sent to my service). If it helps, the client side of my application is both a C# Windows Forms app and an Android app.
I want to save the file on the server with the same file name as the client side. Also I have to check the file type to make sure it is allowed on the server. (the file can be .pdf , .jpg , .jpeg or .zip)
Now is there a way to extract file info from $file_content
variable?