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.