-2

I'm getting the error below... HP Warning: implode() [function.implode]: Argument must be an array

if (!empty($_FILES) && in_array('adjunto', array_keys($_FILES) ) ) {
    $mail->AddAttachment( $_FILES['adjunto']['tmp_name'],$_FILES['adjunto']['name'] );        
}               
error_log(" Files ".implode("",array_keys($_FILES)).' '.implode( array_keys($_FILES['adjunto']) ).date('Y/m/d H:i:s')."\n",3,"./adjuntos/log.log");
$mail->Send();
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • @Jeff `implode()` can be called with one argument, it's the array and the delimiter defaults to an empty string. – Barmar Jan 09 '18 at 22:33
  • FYI, `in_array('adjunto', array_keys($_FILES)` can be simplified to `array_key_exists($_FILES, 'adjunto')` or `isset($_FILES['adjunto'])` – Barmar Jan 09 '18 at 22:37

1 Answers1

0

Your error_log() call is not inside the if block. So it will try to use array_keys($_FILES['adjunto']) even if this key doesn't exist. That will return null, and then you'll try to use implode(null).

The simple solution is to move the error_log() inside the if.

if (!empty($_FILES) && in_array('adjunto', array_keys($_FILES) ) ) {
    $mail->AddAttachment( $_FILES['adjunto']['tmp_name'],$_FILES['adjunto']['name'] );      
    error_log(" Files ".implode("",array_keys($_FILES)).' '.implode( array_keys($_FILES['adjunto']) ).date('Y/m/d H:i:s')."\n",3,"./adjuntos/log.log");  
}               

$mail->Send();
Barmar
  • 741,623
  • 53
  • 500
  • 612