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
https://forums.phpfreaks.com/topic/249460-_filesnamesize-enquiry/
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.

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;

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.