/** * This method converts a given input stream into a local file if required and return the * path to the local file. * * @param Customweb_Core_Stream_IInput $inputStream */ public static function getLocalFilePath(Customweb_Core_Stream_IInput $inputStream) { // In case we get a file input stream, we can simply return the path of the // file. if ($inputStream instanceof Customweb_Core_Stream_Input_File) { return $inputStream->getFilePath(); } $tempDir = Customweb_Core_Util_System::getTemporaryDirPath() . self::TEMP_PATH_PREFIX; if (!file_exists($tempDir)) { mkdir($tempDir, 0770, true); } // Make sure we get a identifier which does not cause any issues on file system: $fileName = sha1($inputStream->getSystemIdentifier()); if (preg_match('/^[0-9]/i', $fileName)) { $fileName = 'd' . $fileName; } $output = new Customweb_Core_Stream_Output_File($tempDir . '/' . $fileName); $output->writeStream($inputStream); return $output->getFilePath(); }
public function writeStream(Customweb_Core_Stream_IInput $inputStream) { $data = $inputStream->read(); $this->write($data); }