public function store($user, $imageIdentifier, $imageData)
{
if (!is_writable($this->params['dataDir'])) {
throw new StorageException('Could not store image', 500);
}
if ($this->imageExists($user, $imageIdentifier)) {
return touch($this->getImagePath($user, $imageIdentifier));
}
$imageDir = $this->getImagePath($user, $imageIdentifier, false);
$oldUmask = umask(0);
if (!is_dir($imageDir)) {
mkdir($imageDir, 0775, true);
}
umask($oldUmask);
$imagePath = $imageDir . '/' . $imageIdentifier;
$bytesWritten = file_put_contents($imagePath, $imageData);
// if write failed or 0 bytes were written (0 byte input == fail), or we wrote less than expected
if (!$bytesWritten || $bytesWritten < strlen($imageData)) {
throw new StorageException('Failed writing file (disk full? zero bytes input?) to disk: ' . $imagePath, 507);
}
return true;
}