Jump to content

$_FILES['name']['size'] enquiry


j.smith1981

Recommended Posts

When you try and upload files using a size limiting feature, when you consider $_FILES['form_element']['size'] what actually is this measured in again?

 

I seem to have forgotten what it's actually measured in, if I was to say a limit on $_FILES['myform_file_upload']['size'] < 20000, what does the 20000 actually mean?

 

Any help is appreciated,

Jeremy.

Link to comment
Share on other sites

Oh of course, how would you then make it so that if say it was above 2mb big, how would you say the file was whatever the size of it was?

 

How would you make it so it's more readable than just saying say 2000kbytes? So when a first comma should be in there, but making that like 2mb just as a bare example?

 

Just something out of pure interest.

 

Thank you though for clearing that up for me!

Jeremy.

Link to comment
Share on other sites

1. starter code here.. you will need to add to this

$errors = array();
if($_FILES['image']['size'] > 2097152){
      $errors[] = "File is too large, 2MB is the maximum file size.";
}

 

you would then display your $errors variable if an error has occurred.

 

2. don't fully understand your second question, but i think you want something like this..

$megabyte = 1048576; // bytes in megabyte
$bytes = $_FILES['image']['size'];
$total_megabytes = $bytes / $megabyte;

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.