Saves an embedded file

@param string Key
@param int Index of the file, defaults to 0
@param string Target path where the file should be saved, including the filename

@return bool Operation status
430348
public function SaveFile($Key, $Index = 0, $TargetPath = '')
	{
		if (!isset($this->Data[$Key]))
		{
			return false;
		}
		if (!isset($this->Data[$Key][$Index]))
		{
			return false;
		}

		// Returing false if it is an image URL
		if (stripos($this->Data[$Key][$Index]['Value'], 'uri:') === 0)
		{
			return false;
		}

		if (is_writable($TargetPath) || (!file_exists($TargetPath) && is_writable(dirname($TargetPath))))
		{
			$RawContent = $this->Data[$Key][$Index]['Value'];
			if (isset($this->Data[$Key][$Index]['Encoding']) && $this->Data[$Key][$Index]['Encoding'] == 'b')
			{
				$RawContent = base64_decode($RawContent);
			}
			$Status = file_put_contents($TargetPath, $RawContent);
			return (bool)$Status;
		}
		else
		{
			throw new Exception('vCard: Cannot save file ('.$Key.'), target path not writable ('.$TargetPath.')');
		}
		return false;
	}
1323335
public function DecryptFile($path, $key)
	{
		if (!file_exists($path))
		{
			throw new GrabzItException("File: " . $path . " does not exist", GrabzItException::FILE_NON_EXISTANT_PATH);
		}
		$data = file_get_contents($path);
		file_put_contents($path, $this->Decrypt($data, $key));
		return true;
	}
351142
public function set($key, $data) {
    $path = $this->getFileName($key, TRUE);
    file_put_contents($path, json_encode($data));
  }
694453
public function lget($key, $index)
    {
        try {
            return $this->redis->lget($key, $index);
        } catch (\RedisException $e) {
            die("Error!: " . $e->getMessage() . "<br/>");
        }
    }
848053
protected function lock($key)
    {
        $path = $key.'.lock';

        for ($i = 0; $i < 25; ++$i) {
            try {
                $this->filesystem->write($path, '');

                return true;
            } catch (FileExistsException $e) {
                usleep(200);
            }
        }

        return false;
    }
117960
public function write($key, $data)
    {
        if ($data === '' || !$this->_init) {
            return false;
        }

        $key = $this->_key($key);

        if ($this->_setKey($key, true) === false) {
            return false;
        }

        $lineBreak = "\n";

        if ($this->_config['isWindows']) {
            $lineBreak = "\r\n";
        }

        if (!empty($this->_config['serialize'])) {
            if ($this->_config['isWindows']) {
                $data = str_replace('\\', '\\\\\\\\', serialize($data));
            } else {
                $data = serialize($data);
            }
        }

        $duration = $this->_config['duration'];
        $expires = time() + $duration;
        $contents = implode([$expires, $lineBreak, $data, $lineBreak]);

        if ($this->_config['lock']) {
            $this->_File->flock(LOCK_EX);
        }

        $this->_File->rewind();
        $success = $this->_File->ftruncate(0) &&
            $this->_File->fwrite($contents) &&
            $this->_File->fflush();

        if ($this->_config['lock']) {
            $this->_File->flock(LOCK_UN);
        }
        $this->_File = null;

        return $success;
    }
1278057
protected function fileUrlAndKey($key)
    {

        if (isset($this->keyUrlCache[$key])) {
            return $this->keyUrlCache[$key];
        }

        $parts = explode('.', $key);
        $url = $this->urlOrFail();
        $partCount = count($parts);

        if ($partCount <= $this->nestingLevel) {
            $minLength = $this->nestingLevel+1;
            $msg = "The key segments has to have a minimum count of $minLength (nesting level: $this->nestingLevel)";
            throw (new KeyLengthException($msg))->setMinSegments($minLength);
        }

        $subKey = [];

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


            if ($i < $this->nestingLevel) {
                $url = $url->append($parts[$i]);
                continue;
            }


            if ($i == $this->nestingLevel) {
                $url = $url->append($this->fileName($parts[$i]));
                continue;
            }

            $subKey[] = $parts[$i];
        }

        $this->keyUrlCache[$key] = [$url, implode('.', $subKey)];

        return $this->keyUrlCache[$key];

    }
741522
public function save($key, $data, $force = false, $ttl = 1440) {
        $ttl = $ttl * 60; // Minutes to Seconds
        // Store result from last query for checking if cache is existing
        // This will avoid locked database error for sqlite3
        $cache_exists = $this->exists($key);

        if (!$cache_exists || $force) {
            // Build data into a array
            $data = [
                'date_created' => time(),
                'ttl' => $ttl,
                'data' => $data
            ];
            
            file_put_contents($this->_storage_path . $this->_encrypt($key), base64_encode(serialize($data)));
            
            return true;
        }
        
        return false;
    }
839147
protected function _update_index($key)
	{
		// get the current index information
		list($identifier, $sections, $index) = $this->_get_index();

		// store the key in the index and write the index back
		$index[$identifier] = array($key, $this->created);
		apc_store($this->config['cache_id'].$sections, array_merge($index, array($identifier => array($key,$this->created))), 0);

		// get the directory index
		$index = apc_fetch($this->config['cache_id'].'__DIR__');

		if (is_array($index))
		{
			if (!in_array($this->config['cache_id'].$sections, $index))
			{
				$index[] = $this->config['cache_id'].$sections;
			}
		}
		else
		{
			$index = array($this->config['cache_id'].$sections);
		}

		// update the directory index
		apc_store($this->config['cache_id'].'__DIR__', $index, 0);
	}
757927
public function get($key)
    {
        $filename = $this->_filename($key);
        if (!file_exists($filename)) {
            return false;
        }

        $tmp_value = file_get_contents($filename);
        $expire    = (int) substr($tmp_value, 13, 24);

        // echo time()."<br />\n";
        // echo $expire."<br />\n";
        // echo substr($tmp_value,23);exit;

        if ($expire != 0 && time() < $expire) {
            return unserialize(substr($tmp_value, 23));
        } else {
            return false;
        }
    }
99874
function saveFile($pFileName, $pContent)
    {
        $directory = \dirname($pFileName);

        if (!\is_dir($directory)) {
            try {
                $madeDir = \mkdir($directory, 0755, TRUE);

            } catch (\Exception $err) {
                throw new \Exception("mkdir: Unable make directory '{$directory}'.");
            }
        }

        // Save data to a file.
        $fileSaved = \file_put_contents($pFileName, $pContent); //, \LOCK_EX );

        if ($fileSaved === FALSE) {
            throw new \Exception("file_put_contents: Unable to save file '{$pFileName}'.");
        }

        return $fileSaved;
    }
913256
protected function _update_index($key)
	{
		// get the current index information
		list($identifier, $sections, $index) = $this->_get_index();

		// store the key in the index and write the index back
		$index[$identifier] = array($key, $this->created);
		xcache_set($this->config['cache_id'].$sections, array_merge($index, array($identifier => array($key,$this->created))));

		// get the directory index
		$index = xcache_get($this->config['cache_id'].'__DIR__');

		if (is_array($index))
		{
			if (!in_array($this->config['cache_id'].$sections, $index))
			{
				$index[] = $this->config['cache_id'].$sections;
			}
		}
		else
		{
			$index = array($this->config['cache_id'].$sections);
		}

		// update the directory index
		xcache_set($this->config['cache_id'].'__DIR__', $index, 0);
	}
350837
protected function storeUploadedFile( $target, $contents )
    {
        $dir = self::tempDirectory() . '/' . md5( microtime() . '-' . $target );
        $filePath = $dir . '/' . basename( $target );

        if ( !file_exists( $dir ) )
        {
            eZDir::mkdir( $dir, false, true );
        }

        $result = file_put_contents( $filePath, $contents );
        if ( !$result )
        {
            $result = file_exists( $filePath );
        }

        if ( $result )
        {
            return $filePath;
        }
        return false;
    }
566699
public function hasKey(string $key): bool
    {
        return $key && strpos($key, '@@') === false && file_exists($this->getPathFromKey($key));
    }
809000
public void saveLOBFile(Key key, File lobFile)
    {
        try
        {
            FileInputStream fis = new FileInputStream(lobFile);
            Version version = kvStore.putLOB(key, fis, client.getDurability(), client.getTimeout(),
                    client.getTimeUnit());
        }
        catch (FileNotFoundException e)
        {
            log.warn("Unable to find file " + lobFile + ". This is being omitted, Caused by:" + e + ".");
        }
        catch (IOException e)
        {
            log.warn("IOException while writing file " + lobFile + ". This is being omitted. Caused by:" + e + ".");
        }
    }
1072034
public function copy($source, $target) {
        // using mark.
        if ('@' == $source[0]) $source = $this->as($source);
        if ('@' == $target[0]) $target = $this->as($target);

        // copy file.
        if (is_file($source)) return copy($source, $target);

        // copy directory.
        $handle = opendir($source);
        while (false !== ($name = readdir($handle))) {
            if ('.' == $name or '..' == $name) continue;
            $subsource = $source.self::DS.$name;
            $subtarget = $target.self::DS.$name;
            if (!$this->copy($subsource, $subtarget)) return false;
        }
        closedir($handle);
        return true;
    }
840658
public function staticAction($key)
    {
        if ($key && is_array($this->staticUriMocks) && array_key_exists($key, $this->staticUriMocks)) {
            $config = $this->staticUriMocks[$key];
            $this->response->setHeader('Content-Type', $config['contentType']);
            return file_get_contents($config['path']);
        }

        throw new TargetNotFoundException();
    }