What could be causing the "Unable to open" error when trying to write a thumbnail to a directory using GD-Lib in PHP?

The "Unable to open" error when trying to write a thumbnail to a directory using GD-Lib in PHP could be caused by incorrect file permissions on the directory where the thumbnail is being saved. To solve this issue, make sure that the directory has the correct permissions set to allow PHP to write to it.

// Check and set correct permissions on the directory
$thumbnailDirectory = 'path/to/thumbnail/directory';
if (!is_dir($thumbnailDirectory)) {
    mkdir($thumbnailDirectory, 0777, true);
} else {
    chmod($thumbnailDirectory, 0777);
}

// Your code to create and save the thumbnail using GD-Lib