| 164 | | if ($fp) { |
|---|
| 165 | | |
|---|
| 166 | | // yes. exclusive lock for writing. |
|---|
| 167 | | flock($fp, LOCK_EX); |
|---|
| 168 | | |
|---|
| 169 | | // don't need the 3rd param (byte length) because Solar has |
|---|
| 170 | | // already turned off magic_quotes_runtime. |
|---|
| 171 | | // <http://php.net/fwrite> |
|---|
| 172 | | fwrite($fp, $data); |
|---|
| 173 | | |
|---|
| 174 | | // add a .serial file? (do this while the file is locked to avoid |
|---|
| 175 | | // race conditions) |
|---|
| 176 | | if ($serial) { |
|---|
| 177 | | // use this instead of touch() because it supports stream |
|---|
| 178 | | // contexts. |
|---|
| 179 | | file_put_contents($file . '.serial', null, LOCK_EX, $this->_context); |
|---|
| 180 | | } else { |
|---|
| 181 | | // make sure no serial file is there from any previous entries |
|---|
| 182 | | // with the same name |
|---|
| 183 | | @unlink($file . '.serial', $this->_context); |
|---|
| 184 | | } |
|---|
| 185 | | |
|---|
| 186 | | // unlock and close, then done. |
|---|
| 187 | | flock($fp, LOCK_UN); |
|---|
| 188 | | fclose($fp); |
|---|
| 189 | | return true; |
|---|
| 190 | | } |
|---|
| 191 | | |
|---|
| 192 | | // could not open the file for writing. |
|---|
| 193 | | return false; |
|---|
| | 185 | if (! $fp) { |
|---|
| | 186 | // could not open the file for writing. |
|---|
| | 187 | return false; |
|---|
| | 188 | } |
|---|
| | 189 | |
|---|
| | 190 | // set exclusive lock for writing. |
|---|
| | 191 | flock($fp, LOCK_EX); |
|---|
| | 192 | |
|---|
| | 193 | // don't need the 3rd param (byte length) because Solar has |
|---|
| | 194 | // already turned off magic_quotes_runtime. |
|---|
| | 195 | // <http://php.net/fwrite> |
|---|
| | 196 | fwrite($fp, $data); |
|---|
| | 197 | |
|---|
| | 198 | // add a .serial file? (do this while the file is locked to avoid |
|---|
| | 199 | // race conditions) |
|---|
| | 200 | if ($serial) { |
|---|
| | 201 | // use this instead of touch() because it supports stream |
|---|
| | 202 | // contexts. |
|---|
| | 203 | file_put_contents($file . '.serial', null, LOCK_EX, $this->_context); |
|---|
| | 204 | } else { |
|---|
| | 205 | // make sure no serial file is there from any previous entries |
|---|
| | 206 | // with the same name |
|---|
| | 207 | @unlink($file . '.serial', $this->_context); |
|---|
| | 208 | } |
|---|
| | 209 | |
|---|
| | 210 | // unlock and close, then done. |
|---|
| | 211 | flock($fp, LOCK_UN); |
|---|
| | 212 | fclose($fp); |
|---|
| | 213 | return true; |
|---|
| | 214 | |
|---|
| 374 | | return $this->_path . hash('md5', $key); |
|---|
| | 395 | if ($this->_config['hash']) { |
|---|
| | 396 | return $this->_path . hash('md5', $key); |
|---|
| | 397 | } else { |
|---|
| | 398 | // try to avoid file traversal exploits |
|---|
| | 399 | $key = str_replace('..', '_', $key); |
|---|
| | 400 | // colons mess up Mac OS X |
|---|
| | 401 | $key = str_replace(':', '_', $key); |
|---|
| | 402 | // done |
|---|
| | 403 | return $this->_path . $key; |
|---|
| | 404 | } |
|---|