Jump to content

PHP file size


phpmaster57

Recommended Posts

So, 100MB is equal to 100000000 Bytes (in decimal), and 104857600 Bytes (in binary), for PHP which version would we use for checking max filesize. My current function:

public function convertToBytes($from){
		$number=substr($from,0,-1);
		switch(strtoupper(substr($from,-1))){
			case "K":
            return $number*1024;
			case "M":
            return $number*pow(1024,2);
			case "G":
            return $number*pow(1024,3);
			case "T":
            return $number*pow(1024,4);
			case "P":
            return $number*pow(1024,5);
			default:
            return $from;
		}
	}

This function converts 100MB to 104857600 bytes. But when comparing it against $_FILES['file']['size'] it will allow the user to upload a 104MB file instead of 100MB file how can we fix this?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.