本文整理汇总了PHP中ET::uploader方法的典型用法代码示例。如果您正苦于以下问题:PHP ET::uploader方法的具体用法?PHP ET::uploader怎么用?PHP ET::uploader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ET
的用法示例。
在下文中一共展示了ET::uploader方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: uploadHeaderImage
/**
* Upload a header image.
*
* @return void
*/
protected function uploadHeaderImage($form)
{
$uploader = ET::uploader();
try {
// Validate and get the uploaded file from this field.
$file = $uploader->getUploadedFile("forumHeaderImage");
// Save it as an image, restricting it to a maximum size.
$logo = $uploader->saveAsImage($file, PATH_UPLOADS . "/logo", 500, 85, "max");
$logo = str_replace(PATH_UPLOADS, "uploads", $logo);
// Delete the old logo (if we didn't just overwrite it.)
if ($logo != C("esoTalk.forumLogo")) {
@unlink(C("esoTalk.forumLogo"));
}
return $logo;
} catch (Exception $e) {
// If something went wrong up there, add the error message to the form.
$form->error("forumHeaderImage", $e->getMessage());
}
}
示例2: action_thumb
public function action_thumb($attachmentId = false)
{
if (!($attachment = $this->getAttachment($attachmentId))) {
return;
}
$model = ET::getInstance("attachmentModel");
$path = $model->path() . $attachmentId . $attachment["secret"];
$thumb = $path . "_thumb";
if (!file_exists($thumb)) {
try {
$uploader = ET::uploader();
$thumb = $uploader->saveAsImage($path, $thumb, 200, 150, "crop");
$newThumb = substr($thumb, 0, strrpos($thumb, "."));
rename($thumb, $newThumb);
$thumb = $newThumb;
} catch (Exception $e) {
return;
}
}
header('Content-Type: ' . $model->mime($attachment["filename"]));
echo file_get_contents($thumb);
}
示例3: action_upload
public function action_upload()
{
// require_once 'qqFileUploader.php';
// $uploader = new qqFileUploader();
// $uploader->inputName = 'qqfile';
// 管理画面で設定されたファイル拡張子(画像のみ)
// Set the allowed file types based on config.
$allowedFileTypes = C("plugin.Attachments.allowedFileTypes");
// 管理画面で設定されたMAXサイズ(デフォルト: 25MB)
// Set the max file size based on config.
$maxSize = C("plugin.Attachments.maxFileSize");
$model = $this->getAttachmentModel();
$id = "";
try {
// アップロード処理
$attachmentId = "";
$uploader = ET::uploader();
$filepath = $uploader->getUploadedFile(self::$file_key, $allowedFileTypes);
if (file_exists($filepath)) {
// ファイルサイズチェック
$size = filesize($filepath);
if ($size > $maxSize) {
// TODO: サイズ超過 エラー時
}
// 元ファイル名
$name = $_FILES[self::$file_key]["name"];
$ext = strtolower(pathinfo($name, PATHINFO_EXTENSION));
if ($ext != "gif") {
// gif 以外はjpg で保存
$ext = "jpg";
}
// ファイル名
$baseName = pathinfo($name, PATHINFO_BASENAME);
// $baseName = pathinfo($filepath, PATHINFO_FILENAME) .$ext;
$attachmentId = SwcUtils::createUniqKey(13);
// ランダム文字列
$secret = generateRandomString(13, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890");
// 保存先ファイルパス
$destPath = $model->path() . $attachmentId . $secret . "." . $ext;
// MAX値超過する場合 リサイズする
$outputFile = $uploader->saveAsImage($filepath, $destPath, SWC_IMG_MAX_W, SWC_IMG_MAX_H);
// 画像データ
$imgFile = file_get_contents($outputFile);
// エンティティ設定
$entity = array("attachmentId" => $attachmentId, "filename" => $baseName, "secret" => $secret, "content" => $imgFile);
$paramPostId = R("postId");
if (preg_match('/^p[0-9]+$/', $paramPostId)) {
// postID がある場合 "p"から始まる
// "p"を除去して登録
$entity["postId"] = substr($paramPostId, 1);
} else {
if (preg_match('/^c[0-9]+$/', $paramPostId)) {
// 会話ID を設定 "c"から始まる
// 新規の場合、"c0"が設定されている
// アップロード時は"c" を付けたまま一時登録する
$entity["conversationId"] = $paramPostId;
}
}
// sessId取得
$sessId = ET::$session->getSessId();
$entity["sessId"] = $sessId;
$model->create($entity, false);
}
} catch (Exception $e) {
// TODO:
return;
}
$result = array();
if ($attachmentId) {
// OK の場合
$result["success"] = 1;
$result["uploadName"] = $baseName;
$result["attachmentId"] = $attachmentId;
} else {
// NG
$result["success"] = 0;
}
header("Content-Type: text/plain");
echo json_encode($result);
}
示例4: saveAvatar
/**
* Save the contents of the avatar field when the general settings form is submitted.
*
* @param string $key The name of the field that was submitted.
* @param ETForm $form The form object.
* @param array $preferences An array of preferences to write to the database.
* @return string
*/
public function saveAvatar($key, $form, &$preferences)
{
if (empty($_FILES[$key]["tmp_name"])) {
return;
}
$uploader = ET::uploader();
try {
// Validate and get the uploaded file from this field.
$file = $uploader->getUploadedFile($key);
// Save it as an image, cropping it to the configured avatar size.
$avatar = $uploader->saveAsImage($file, PATH_UPLOADS . "/avatars/" . ET::$session->userId, C("esoTalk.avatars.width"), C("esoTalk.avatars.height"), "crop");
// Update the member's avatarFormat field to the avatar file's extension.
ET::memberModel()->updateById(ET::$session->userId, array("avatarFormat" => pathinfo($avatar, PATHINFO_EXTENSION)));
} catch (Exception $e) {
// If something went wrong up there, add the error message to the form.
$form->error($key, $e->getMessage());
}
}
示例5: action_thumb
public function action_thumb($attachmentId = false)
{
if (!($attachment = $this->getAttachment($attachmentId))) {
return;
}
$model = ET::getInstance("attachmentModel");
//$path = $model->path().$attachmentId.$attachment["secret"];
$path = $model->path() . $attachmentId . '_' . $attachment["filename"];
//$thumb = $path."_thumb";
$thumb = $model->path() . 'thumb_' . $attachmentId . '_' . $attachment["filename"];
$thumb_encode = $model->path() . urlencode('thumb_' . $attachmentId . '_' . $attachment["filename"]);
if (!file_exists(PATH_SAESTOR . $thumb)) {
try {
$uploader = ET::uploader();
$thumb = $uploader->saveAsImage(PATH_SAESTOR . $path, $thumb, 400, 300, "max");
//$newThumb = substr($thumb, 0, strrpos($thumb, "."));
//rename($thumb, $newThumb);
//$thumb = $newThumb;
} catch (Exception $e) {
return;
}
}
//in SAE
$s = new SaeStorage();
if ($s->fileExists(SAESTOR_DOMAIN, $thumb)) {
$url = $s->getUrl(SAESTOR_DOMAIN, $thumb_encode);
redirect($url);
} else {
$this->render404(T("message.attachmentNotFound"), true);
return false;
}
//header('Content-Type: '.$model->mime($attachment["filename"]));
//echo file_get_contents($thumb);
}
示例6: createThumb
/**
* サムネイル画像登録
* @param type $attachment
* @param type $type 1:メイン画像
*/
public function createThumb($attachment, $postId, $type, $isRemove = false)
{
$uploader = ET::uploader();
// 一時ファイルパス取得
$srcPath = $this->getTempFileName($attachment);
$thumbPath = $this->getThumbFileName($srcPath);
if (!file_exists($srcPath) && $attachment["content"]) {
// 元画像なしの場合
file_put_contents($srcPath, $attachment["content"]);
}
// サムネイル画像生成
$thumb = $uploader->saveAsImage($srcPath, $thumbPath, SWC_IMG_THUMB_W, SWC_IMG_THUMB_H, "crop");
$imgFile = file_get_contents($thumb);
// type= 1: メイン画像
$entity = array("thumbId" => $attachment["attachmentId"], "postId" => $postId, "type" => $type, "attachmentId" => $attachment["attachmentId"], "content" => $imgFile);
ET::SQL()->insert("thumb")->set("thumbId", $attachment["attachmentId"])->set("postId", $postId)->set("type", $type)->set("attachmentId", $attachment["attachmentId"])->set("content", $imgFile)->exec();
if ($isRemove) {
// 削除フラグON
$this->removeFile($attachment);
}
}
示例7: uploadBackgroundImage
/**
* Upload a background image.
*
* @return void
*/
protected function uploadBackgroundImage($form)
{
$uploader = ET::uploader();
try {
// Validate and get the uploaded file from this field.
$file = $uploader->getUploadedFile("bodyImageFile");
// Save it as an image, restricting it to a maximum size.
$bg = $uploader->saveAsImage($file, PATH_UPLOADS . "/bg", 1, 1, "min");
$bg = str_replace(PATH_UPLOADS, "uploads", $bg);
// Delete the old background image (if we didn't just overwrite it.)
if ($bg != C("skin.Default.bodyImage")) {
@unlink(C("skin.Default.bodyImage"));
}
return $bg;
} catch (Exception $e) {
// If something went wrong up there, add the error message to the form.
$form->error("bodyImageFile", $e->getMessage());
}
}