public function append_post($filename, $text, $image) { if (empty($text) and empty($image)) { return false; } if (substr($filename, -3) != '.md') { $filename .= '.md'; } if (IS_SAE) { $path = 'posts/' . $filename; } else { $path = $this->posts_path . $filename; } if (!s_file_exists($path)) { $this->_error = $filename . ' is not exist'; return false; } $content = s_read($path); if ($text) { $content .= "\n\n" . $text; if (s_write($path, $content) === false) { $this->_error = 'failed to write'; return false; } } if ($image) { $ret = $this->image_upload($image); if ($ret === false) { return false; } else { $image_filename = basename($ret); $content .= "\n\n" . "![](images/{$image_filename})"; if (s_write($path, $content) === false) { $this->_error = 'failed to write'; return false; } else { return $filename; } } } return $filename; }
/** * Get image properties * * A helper function that gets info about the file * * @access public * @param string * @return mixed */ function get_image_properties($path = '', $return = FALSE) { // For now we require GD but we should // find a way to determine this using IM or NetPBM if ($path == '') { $path = $this->full_src_path; } //SAE if (s_file_exists($path) === FALSE) { $this->set_error('imglib_invalid_path'); return FALSE; } // SAE 要先读出来写入临时目录,再获取大小 $x = explode('/', $path); $img_name = end($x); file_put_contents(SAE_TMP_PATH . $img_name, s_read($path)); $vals = @getimagesize(SAE_TMP_PATH . $img_name); $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); $mime = isset($types[$vals['2']]) ? 'image/' . $types[$vals['2']] : 'image/jpg'; if ($return == TRUE) { $v['width'] = $vals['0']; $v['height'] = $vals['1']; $v['image_type'] = $vals['2']; $v['size_str'] = $vals['3']; $v['mime_type'] = $mime; return $v; } $this->orig_width = $vals['0']; $this->orig_height = $vals['1']; $this->image_type = $vals['2']; $this->size_str = $vals['3']; $this->mime_type = $mime; return TRUE; }