我正在开发一款Android应用。在我的应用程序中,我需要将图像上传到服务器。我在服务器端使用PHP(Laravel 5.2)。我正在使用Volley与服务器连接。但在我上传之前,我在android中压缩了图像bofore上传。所以我的问题是如何在服务器端验证上传图像的文件大小?请检查下面的代码。
这是我在Android中压缩的方式
public String getStringImage(Bitmap bmp){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
if(imgExtension!=null && imgExtension.equals("png"))
{
bmp.compress(Bitmap.CompressFormat.PNG, 100, baos);
}
else{
bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos);
}
byte[] imageBytes = baos.toByteArray();
String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
return encodedImage;
}
所以我将压缩后的字符串放到图像字段并上传到服务器。
我像这样在服务器端上传。
//I want to retrieve the uploaded image size here before upload
file_put_contents("my_image.jpg", base64_decode($_POST['image']));
那么我如何评论文件大小呢?