Skip to content
Advertisement

How can i remove images with php when there is a Array to string conversion?

I am trying to remove images in a folder with php but i seem to be getting this error: Notice: Array to string conversion in C:xampphtdocsteadmisedupload.php on line 89

Why can’t i add string value with array value?

        $stmt = $pdo->query('SELECT image FROM posts WHERE post_id =' . $number . ' AND NOT image="noimage.png";');
        $allFileNames = $stmt->fetchAll();


        $countAllNames = count($allFileNames);


        for($i=0; $i < $countAllNames; $i++) {

            $path = "uploads/" . $allFileNames[$i];  // something is wrong in here
            if(!unlink($path)) {
                echo "You have an error!";
                exit();
            }
        }

Advertisement

Answer

$allFileNames[$i] is a associative array.

You need to use $allFileNames[$i]["post_id"] instead.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement