Jump to content

file size more than


maxwel

Recommended Posts

<?php

ini_set('upload_max_filesize', '70M');

ini_set('post_max_size', '70M');

ini_set('max_input_time', 6000);

ini_set('max_execution_time', 300000);

 

 

$f = 'path';

 

$obj = new COM ( 'scripting.filesystemobject' );

 

if ( is_object ( $obj ) )

{

$ref = $obj->getfolder ( $f );

 

//echo 'Directory: ' . $f . ' => Size: ' . $ref->size;

 

$obj = null;

}

else

{

//echo 'can not create object';

}

 

if ( $ref->size < 32212254720){

 

 

 if (($_FILES["fileToUpload"]["type"] == "audio/mp3")

  || ($_FILES["fileToUpload"]["type"] == "audio/wav")

  || ($_FILES["fileToUpload"]["type"] == "audio/mpeg")

   && ($_FILES["fileToUpload"]["size"] >= 26214400)

 && ($_FILES["fileToUpload"]["size"]<= 70000000)

 )

   {

 

things done

 


else

   {

echo error

}

echo error space if full

}

Link to comment
https://forums.phpfreaks.com/topic/278854-file-size-more-than/#findComment-1434510
Share on other sites

Please use [code] tags when posting code.

 

if (($_FILES["fileToUpload"]["type"] == "audio/mp3")
	|| ($_FILES["fileToUpload"]["type"] == "audio/wav")
	|| ($_FILES["fileToUpload"]["type"] == "audio/mpeg")
	&& ($_FILES["fileToUpload"]["size"] >= 26214400)
	&& ($_FILES["fileToUpload"]["size"] <= 70000000)
)
Operator precedence. && has higher precedence than ||, meaning a || b && c works like a || (b && c). Rearranging your code,

$mp3 = ($_FILES["fileToUpload"]["type"] == "audio/mp3");
$wav = ($_FILES["fileToUpload"]["type"] == "audio/wav");
$mpeg = ($_FILES["fileToUpload"]["type"] == "audio/mpeg")
	&& ($_FILES["fileToUpload"]["size"] >= 26214400)
	&& ($_FILES["fileToUpload"]["size"] <= 70000000);

if ($mp3 || $wav || $mpeg) {
Use parentheses to change that behavior.

if (
	(($_FILES["fileToUpload"]["type"] == "audio/mp3")
		|| ($_FILES["fileToUpload"]["type"] == "audio/wav")
		|| ($_FILES["fileToUpload"]["type"] == "audio/mpeg"))
	&& ($_FILES["fileToUpload"]["size"] >= 26214400)
	&& ($_FILES["fileToUpload"]["size"] <= 70000000)
)
Link to comment
https://forums.phpfreaks.com/topic/278854-file-size-more-than/#findComment-1434513
Share on other sites

still dont work and it pass it as if its higher than 25 mb :S, sigh

 

i used that 

$mp3 = ($_FILES["fileToUpload"]["type"] == "audio/mp3");
$wav = ($_FILES["fileToUpload"]["type"] == "audio/wav");
$mpeg = ($_FILES["fileToUpload"]["type"] == "audio/mpeg")
    && ($_FILES["fileToUpload"]["size"] >= 26214400)
    && ($_FILES["fileToUpload"]["size"] <= 70000000);

if ($mp3 || $wav || $mpeg) {

instead of that part

 

 if (($_FILES["fileToUpload"]["type"] == "audio/mp3")
  || ($_FILES["fileToUpload"]["type"] == "audio/wav")
  || ($_FILES["fileToUpload"]["type"] == "audio/mpeg")
   && ($_FILES["fileToUpload"]["size"] >= 26214400)
 && ($_FILES["fileToUpload"]["size"]<= 70000000)
 )
   {
Link to comment
https://forums.phpfreaks.com/topic/278854-file-size-more-than/#findComment-1434516
Share on other sites

Operator precedence. && has higher precedence than ||, meaning a || b && c works like a || (b && c). Rearranging your code,

 

 
Not technically true. ANDs and ORs are executed left to right - assuming there are no parenthetical conditions. EDIT: But, in a way, the nature of AND does make that true based upon the end result. But, ANDs aren't processed before ORs
 
Here are all the possible combinations using that example:
if(true || true && true) { echo "A"; }
if(true || true && false) { echo "B"; }
if(true || false && true) { echo "C"; }
if(true || false && false) { echo "D"; }
if(false || true && true) { echo "E"; }
if(false || true && false) {  echo "F"; }
if(false || false && true) { echo "G"; }
if(false || false && false) { echo "H"; }
 
The output will be ABCDE. ABCD are true for the lone fact that "a" is true. Once the parser sees that the first condition is true and there is an OR condition it exits the condition check entirely and doesn't check b & c at all. It's easy to verify this
 
function test($bool)
{
    echo "X"; return $bool;
}

if(test(true) || test(true) && test(true)) { echo "A<br>"; } //Output: XA
//Exits after the first condition check
 
if(test(false) || test(true) && test(true)) { echo "E<br>"; } //Output: XXXE
//Has to check all three conditions

 

That is why you can use an isset() check for a POST var to prevent warning messages

//This will produce a warning if 'foo' is not set
if($_POST['foo'] == 'bar') { echo "bar"; }
 
//This will NOT produce a warning if 'foo' is not set because it
//will exist after the first false due to the AND condition
if(isset($_POST['foo']) && $_POST['foo'] == 'bar') { echo "bar"; }
Link to comment
https://forums.phpfreaks.com/topic/278854-file-size-more-than/#findComment-1434521
Share on other sites

Not technically true. ANDs and ORs are executed left to right - assuming there are no parenthetical conditions. EDIT: But, in a way, the nature of AND does make that true based upon the end result. But, ANDs aren't processed before ORs

No, what I said is technically true. Read it again: I didn't say they're executed first, I said they have higher precedence. Meanwhile you are also correct about that not affecting the order of evaluation and about short-circuiting.

 

[edit] If && did not have higher precedence than || then your test script would not output "B".

echo (true || true && false) ? "Y" : "N"; // normal
echo ( (true || true) && false ) ? "Y" : "N"; // forced || >= &&
echo ( true || (true && false) ) ? "Y" : "N"; // forced && > ||
YNY
Link to comment
https://forums.phpfreaks.com/topic/278854-file-size-more-than/#findComment-1434541
Share on other sites

still dont work and it pass it as if its higher than 25 mb :S, sigh

 

i used that 

$mp3 = ($_FILES["fileToUpload"]["type"] == "audio/mp3");
$wav = ($_FILES["fileToUpload"]["type"] == "audio/wav");
$mpeg = ($_FILES["fileToUpload"]["type"] == "audio/mpeg")
    && ($_FILES["fileToUpload"]["size"] >= 26214400)
    && ($_FILES["fileToUpload"]["size"] <= 70000000);

if ($mp3 || $wav || $mpeg) {
instead of that part

 

 

 if (($_FILES["fileToUpload"]["type"] == "audio/mp3")
  || ($_FILES["fileToUpload"]["type"] == "audio/wav")
  || ($_FILES["fileToUpload"]["type"] == "audio/mpeg")
   && ($_FILES["fileToUpload"]["size"] >= 26214400)
 && ($_FILES["fileToUpload"]["size"]<= 70000000)
 )
   {

 

And that's the problem: the part you're using is the one I wrote to try to make it more obvious how your code was working. Working incorrectly. The second thing I posted is what you're supposed to use, but you can use variables (like how I did in the other) if you want to make it easier to read.
Link to comment
https://forums.phpfreaks.com/topic/278854-file-size-more-than/#findComment-1434542
Share on other sites

I agree with requinix regarding the use of variables. Makes your code more readable and easier to modify. If you hard code a minimum file size and have to use it multiple times it would be easy to try and change that minimum size and miss one of the instances. My take:

 

$validFileTypes = array('audio/mp3', 'audio/wav', 'audio/mpeg');
$fileType = $_FILES["fileToUpload"]["type"];
$fileSize = $_FILES["fileToUpload"]["size"];
$minFileSize = 26214400;
$maxFileSize = 70000000;


if( in_array($fileType, $validFileTypes)
    && $fileSize >= $minFileSize
    && $fileSize <= $maxFileSize )
{
    //Conditions passed
}
Link to comment
https://forums.phpfreaks.com/topic/278854-file-size-more-than/#findComment-1434544
Share on other sites

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.