function s_read($path) { if (file_exists($path)) { return file_get_contents($path); } else { if (IS_SAE) { if (s_file_exists($path)) { $_s = new SaeStorage(); $_f = _s_get_path($path); return $_s->read($_f['domain'], $_f['filename']); } } else { } } return false; }
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; }
/** * Set the file name * * This function takes a filename/path as input and looks for the * existence of a file with the same name. If found, it will append a * number to the end of the filename to avoid overwriting a pre-existing file. * * @param string * @param string * @return string */ public function set_filename($path, $filename) { if ($this->encrypt_name == TRUE) { mt_srand(); $filename = md5(uniqid(mt_rand())) . $this->file_ext; } //SAE 判断文件是否存在 if (!s_file_exists($path . $filename)) { return $filename; } $filename = str_replace($this->file_ext, '', $filename); $new_filename = ''; for ($i = 1; $i < 100; $i++) { if (!s_file_exists($path . $filename . $i . $this->file_ext)) { $new_filename = $filename . $i . $this->file_ext; break; } } if ($new_filename == '') { $this->set_error('upload_bad_filename'); return FALSE; } else { return $new_filename; } }