Jump to content

file size more than


maxwel

Recommended Posts

($_FILES["fileToUpload"]["size"] >= 26214400) dont work, i can upload files less than 25 mb still?! is that normal? i upload file that is 800bytes and it works :( any idea how to make it work? or if there is another solution?

 

Thanks in advance,

Maxwel

Link to comment
Share on other sites

<?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

}

Edited by maxwel
Link to comment
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
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)
 )
   {
Edited by maxwel
Link to comment
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"; }
Edited by Psycho
Link to comment
Share on other sites

ok read post more well and got what u said exactly it worked woot woot :)

 

but now i have a question about something else, can i ask it here in that topic aswell? its like need a suggestion from you :)

 

Thanks alot

 

maxwell

Link to comment
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 Edited by requinix
Link to comment
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
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
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.