// child2 = rotate % $allowed = array(90, 270); if (!in_array($this->child2, $allowed)) { dp('HACK: odd rotate %: ' . $this->child2); return; } $session->requireLoggedIn(); $f = File::get($this->child); if ($session->id != $f->uploader) { dp('HACK: tried to rotate photo ' . $this->child . ' which is not uploaded by user ' . $session->id); return; } $im = new ImageRotator($f); $im->rotate($this->child2); $im->render($im->mimetype, File::getUploadPath($f->id)); File::sync($fileId); //updates tblFiles.size js_redirect('u/photo/show/' . $f->id); break; case 'delete': $session->requireLoggedIn(); if ($this->child && confirmed('Are you sure you want to delete this photo?')) { // verify that the owner of the album is current session id $im = File::get($this->child); if ($im->uploader != $session->id) { dp('HACK: tried to delete photo ' . $this->child . ' which is not uploaded by user ' . $session->id); return; } File::delete($this->child); js_redirect('u/album/show/' . $session->id . '/' . $im->category); }
/** * 递增 * * @param string $key * @param int $offset * @param int $lifetime 当递减失则时当作set使用 */ public function increment($key, $offset = 1, $lifetime = 60) { if ($this->is_file_write_disalbed) { return false; } $filename = $this->get_filename_by_key($key); if (!file_exists($filename)) { # 不存在,则设置 return $this->set($key, $offset, $lifetime); } $fh = fopen($filename, 'r+'); if (flock($fh, LOCK_EX)) { $data = trim(fread($fh, filesize($filename))); $expired_setting = $this->get_expired_setting($key, $data); if ($expired_setting) { $buffer = $data + $offset; $lifetime = max($expired_setting['lifetime'], $lifetime); } else { $buffer = $offset; } $data = $this->format_data($lifetime, $buffer); rewind($fh); fwrite($fh, $data); fflush($fh); ftruncate($fh, ftell($fh)); flock($fh, LOCK_UN); $status = true; } else { $status = false; } @fclose($fh); if ($status) { # 同步文件 File::sync($filename, $this->storage); } return $status; }
function index() { File::sync(); return array(); }