Wrong datatype for second argument

Discussion in 'PHP' started by Kuna, Aug 22, 2010.

  1. #1
    This is my script for counting file size in folders, but when I put this script on normal text page it shows error:
    Warning: in_array() [function.in-array]: Wrong datatype for second argument in statistics.php on line 20


    <?php
    if (session_id() == ""){
    session_start();
    }
    $maxupload=1024000000; // in byte
    $dir='jdownloads';
    $notcount=array('index.html','listing.php','descriptionfile.txt');
    dirs($dir);
    $sizeinbyte=($_SESSION[tots]==0)?'0':$_SESSION[tots];
    $_SESSION[tots]=array();
    unset($_SESSION[tots]);
    function dirs($dir){
    global $notcount;
    if ($handle = opendir($dir)) {
    while (false !== ($file = readdir($handle))) {
     if ($file != "." && $file != "..") {
    if(is_dir($dir.'/'.$file)){
    dirs($dir.'/'.$file);
    }else{
    if (!in_array($file, $notcount)) {
    $fl=filesize($dir.'/'.$file);
    $_SESSION[tots]=$_SESSION[tots]+$fl;
    }
    }
    }
    }
    closedir($handle);
    }
    }
    ?>
    PHP:

     
    Kuna, Aug 22, 2010 IP
  2. xenon2010

    xenon2010 Peon

    Messages:
    237
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try not to use globals..

    <?php
    if (session_id() == ""){
    session_start();
    }
    $maxupload=1024000000; // in byte
    $dir='jdownloads';
    $notcount=array('index.html','listing.php','descriptionfile.txt');
    dirs($dir, $notcount);
    $sizeinbyte=($_SESSION[tots]==0)?'0':$_SESSION[tots];
    $_SESSION[tots]=array();
    unset($_SESSION[tots]);
    
    
    function dirs($dir, $notcount){
    if ($handle = opendir($dir)) {
    while (false !== ($file = readdir($handle))) {
     if ($file != "." && $file != "..") {
    if(is_dir($dir.'/'.$file)){
    dirs($dir.'/'.$file);
    }else{
    if (!in_array($file, $notcount)) {
    $fl=filesize($dir.'/'.$file);
    $_SESSION[tots]=$_SESSION[tots]+$fl;
    }
    }
    }
    }
    closedir($handle);
    }
    }
    ?>
    PHP:
     
    xenon2010, Aug 22, 2010 IP
  3. Kuna

    Kuna Well-Known Member

    Messages:
    426
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #3
    not working
     
    Kuna, Aug 23, 2010 IP
  4. Kuna

    Kuna Well-Known Member

    Messages:
    426
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #4
    I just put this
    Error_Reporting(E_ERROR);
    clearstatcache();
    session_start();
    
    PHP:
    Is this good idea?
     
    Kuna, Aug 23, 2010 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    No,

    the error is already being reported, statcache has no effect on this script, and the session is already being stared (and has nothing to do with the error anyway).

    There's a dirs() call in xeons' script where $notcount isn't passed properly, which is probably causing the error.
     
    nico_swd, Aug 23, 2010 IP
  6. xenon2010

    xenon2010 Peon

    Messages:
    237
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    <?php
    if (session_id() == ""){
    session_start();
    }
    
    function dirs($dir, $notcount)
    {
    $file = '';
    
    if ($handle = opendir($dir)) 
    {
    while (false !== ($file = readdir($handle))) 
    {
     if ($file != "." && $file != "..") 
    {
    if(is_dir($dir.'/'.$file))
    {
    dirs($dir.'/'.$file);
    }
    else
    {
    if (!in_array($file, $notcount)) 
    {
    $fl=filesize($dir.'/'.$file);
    $_SESSION[tots]=$_SESSION[tots]+$fl;
    }
    }
    }
    }
    closedir($handle);
    }
    }
    
    
    $maxupload=1024000000; // in byte
    $dir='jdownloads';
    $notcount=array('index.html','listing.php','descriptionfile.txt');
    dirs($dir, $notcount);
    $sizeinbyte=($_SESSION[tots]==0)?'0':$_SESSION[tots];
    $_SESSION[tots]=array();
    unset($_SESSION[tots]);
    
    ?>
    PHP:
    try this one.. although i didnt test it..
     
    xenon2010, Aug 24, 2010 IP
  7. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #7
    Line 18...
     
    nico_swd, Aug 24, 2010 IP
  8. Kuna

    Kuna Well-Known Member

    Messages:
    426
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #8
    thanks I'll try that
     
    Kuna, Aug 24, 2010 IP