problems when deleting unlink file ()

2

I would like to delete a file in the file, and nothing is going well from the following error Strict standards: Only variables should be passed by reference could you guide me to solve this error? I'll be thankful! Image Link:

<a id="photo-'.$resultfotos['id'].'" href="site.php?userid='.$user_id.'&pageid='.$page.'&fotoid='.$resultfotos['id'].'">
   <img src="uploads/photos/'.$resultfotos['foto'].'"/>
</a> 

Link to delete photo:

Delete the photo // I made an include in the page "deletefotos.php" //

<?php 
   $image = end(explode('-',$_GET['photo']));
   $result = Pagina::minhaFoto($imagem,$user_id); 
   if($result['res']){
      if(Pagina::delFoto($idDaimagem)){
         if(file_exists('../uploads/photos'.$result['foto'])){
            unlink('../uploads/photos'.$result['foto']);
         }
      }
   } ?> 

page class, page.class.php

<?php
 static function minhaFoto($imagem){
   $select = self::getConn()->prepare('SELECT 'pagina' FROM 'fotos' WHERE 'id'=? LIMIT 1');
   $select->execute(array($imagem));
   if($select->rowCount()==1){
      $asfoto = $select(PDO::FETCH_ASSOC);
      $dados['res'] = self::myEvent($asfoto['pagina'],$user_id);
      $dados['foto'] = $asfoto['foto'];
      return $d; 
  } 
}

static function delFoto($idDaimagem){
   $del = self::getConn()->prepare('DELETE FROM 'fotos' WHERE 'id'=?');
   return $del->execute(array($idDaimagem));
}     
?>
    
asked by anonymous 24.09.2015 / 22:30

2 answers

3

The problem is that end() expects a reference to be a variable, do the two-step assignment.

Change:

$image = end(explode('-',$_GET['photo']));

To:

$nome = explode('-',$_GET['photo'])
$ext = end($nome);

Watch for signature of functions with & it means that the argument should be passed as reference most of the time.

  

mixed end (array & array)

Related:

Doubt about PHP function 'end'

    
24.09.2015 / 22:33
3

Correct @rray's response. The problem is with end accept only variables, not array expressions. Therefore, this function accepts an argument that is a variable, because it is a parameter with reference.

There is a way to circumvent this limitation of the end function.

So:

function last(array $array)
{
    return end($array);
}

In this way, $array , which is a parameter of last , is passed to end as argument, becoming a reference for end , and may be expression for last .

Example:

echo last(explode('-', '1-2-3')); // Imprime '3'
    
25.09.2015 / 16:50