Error_log issue (PHP Coding Problem)

Discussion in 'PHP' started by Pathan, Oct 19, 2012.

  1. #1
    Hello,

    I am using script to list files today I checked the directory where that script is uploaded and I can see that the error_log file was filled with tons of error messages I downloaded the error_log file and noticed the following errors.

    
    [05-Oct-2012 12:13:56] PHP Warning:  array_multisort() [<a href='function.array-multisort'>function.array-multisort</a>]: Argument #1 is expected to be an array or a sort flag in /home/site/public_html/script/index.php on line 483
    [05-Oct-2012 12:13:56] PHP Warning:  Invalid argument supplied for foreach() in /home/site/public_html/script/index.php on line 484
    
    Code (markup):
    on line 483 and 484 we have the following coding in index.php

    
    	 array_multisort($ftimes2,SORT_DESC,$ftimes);
    	 foreach ($ftimes as $readd) {
    
    PHP:
    Please help.

    -Regards.
     
    Pathan, Oct 19, 2012 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    We might need the code before these lines, where can you see that ftimes is used to contain an array?
     
    EricBruggema, Oct 20, 2012 IP
  3. Pathan

    Pathan Well-Known Member

    Messages:
    2,196
    Likes Received:
    218
    Best Answers:
    0
    Trophy Points:
    165
    #3
    Here is the code:

    foreach ($mp3s as $gftkey => $gftrow) {
    	   if (file_exists($thecurrentdir.$gftrow)) {
    	  $ftimes[$gftkey] = array(filemtime('/home/site/public_html/script/' . $thecurrentdir.$gftrow),$gftrow);
    	  $ftimes2[$gftkey] = array(filemtime('/home/site/public_html/script/' . $thecurrentdir.$gftrow),$gftrow);
    	   }
    	 }
    	 array_multisort($ftimes2,SORT_DESC,$ftimes);
    	 foreach ($ftimes as $readd) {
    	   $newmp3s[] = $readd[1];
    	}
    	$mp3s = $newmp3s;
    	}
    PHP:
     
    Pathan, Oct 20, 2012 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #4
    Anywhere above that are you actually defining ftimes2 as an array before you start plugging values into it? If it's bombing because ftimes2 isn't an array... well there's your problem.

    This would be particularly true if all the file_exists commands return false, as then it might even be undefined... which is something I'd be testing for as well.
     
    deathshadow, Dec 5, 2012 IP
  5. Pathan

    Pathan Well-Known Member

    Messages:
    2,196
    Likes Received:
    218
    Best Answers:
    0
    Trophy Points:
    165
    #5
    R/Sir,

    I am not good at php stuff, can you please explain it in a way that I may understand it and also guide me which code I should remove or modify.

    With Regards.
     
    Pathan, Dec 5, 2012 IP