本文整理汇总了PHP中Uploader类的典型用法代码示例。如果您正苦于以下问题:PHP Uploader类的具体用法?PHP Uploader怎么用?PHP Uploader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Uploader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: changeAvatar
function changeAvatar()
{
if (isset($_POST['avasubmit'])) {
$upload_dir = './images/avatars/';
$cfile = md5($_SESSION['nickname']);
$u = new Uploader();
try {
if (is_file($upload_dir . $cfile . '.jpg')) {
unlink($upload_dir . $cfile . '.jpg');
}
if (is_file($upload_dir . $cfile . '.jpeg')) {
unlink($upload_dir . $cfile . '.jpeg');
}
if (is_file($upload_dir . $cfile . '.png')) {
unlink($upload_dir . $cfile . '.png');
}
if (is_file($upload_dir . $cfile . '.gif')) {
unlink($upload_dir . $cfile . '.gif');
}
$cfile = $u->Upload('avach', $upload_dir, $cfile);
} catch (Exception $e) {
$error = $e->getMessage();
}
$sql = "UPDATE useravatar SET avatar='" . $cfile . "' WHERE id=(SELECT avatar_id FROM users WHERE id=" . $_SESSION['id'] . ");";
$this->db->query($sql);
$_SESSION['avatar'] = $cfile;
}
}
示例2: fileUploadBlock
public static function fileUploadBlock()
{
if (self::$invalid) {
return;
}
i18n::set('admin');
$uploader = new Uploader('editFiles', 'EditPage::handleUpload', false, array('multi' => true));
queue_js_string("/*\$(function(){\$('.view-uploads').overlay({\n\tmask: {\n\t\tcolor: '#000',\n\t\tloadSpeed: 200,\n\t\topacity: 0.7\n\t},\n\n\tcloseOnClick: true\n});});*/");
$uploadedButton = sprintf("<a href='#' class='action view-uploads' rel='#cc_uploaded_overlay'>%s%s</a>", icon('folder_picture'), __('admin', 'view-all-files'));
$uploadedFiles = <<<EOT
<div class="cc_uploaded_files">
{$uploadedButton}
\t<div id="cc_uploaded_overlay" class="cc_modal">
\t\t<h2>%s</h2>
\t\t<ul class="cc_file_list">
\t\t\t%s
\t\t</ul>
\t</div>
</div>
EOT;
//foreach(Uploads::getAllFiles() as $)
$r .= sprintf("<h3>%s</h3>%s%s", __('upload-files'), sprintf($uploadedFiles, __('uploaded-files'), $files), $uploader->createHTML());
i18n::restore();
return $r;
}
示例3: upload
public function upload()
{
//检查登录
$this->_login();
//单文件
if (!$_FILES || $_FILES["file"]["error"] > 0) {
echo '图片不能为空!';
throw new Exception('exit');
}
//处理上传的图片
$dir = 'goods/';
$upload = new Uploader($_FILES, $dir);
//保存图片
if ($upload->save()) {
$data['goods_photo'] = $upload->getUrl();
//图片路径
}
$da = array();
$da = $this->_getPost();
$data_new = array_merge($data, $da);
AdminGoodsM::add($data_new);
//跳转到未出售商品列表
$url = url('admin', 'admingoods::unsale');
header('Location:' . $url);
throw new Exception('exit');
}
示例4: save
function save($package)
{
$Filter = new Filter();
$name = $this->getName($Filter->get($package, 'name', null));
if ($Filter->get($package, 'error', false)) {
// An HTTP error occurred
return false;
} else {
if (empty($name)) {
// An empty file name was posted
return false;
} else {
if ($this->exists($name)) {
return false;
}
}
}
$Uploader = new Uploader(array("application/zip"), array(SB_TMP_DIR));
list($result, $tmpfile) = $Uploader->upload($package, SB_TMP_DIR);
if (intval($result) != 1) {
// The file was not uploaded
return false;
}
if ($this->unzip($tmpfile, $this->directory)) {
return true;
}
unlink($tmpfile);
return false;
}
示例5: save
function save($package)
{
$Filter = new Filter();
$name = $this->getName($Filter->get($package, 'name', null));
if ($Filter->get($package, 'error', false)) {
// An HTTP error occurred
return false;
} else {
if (empty($name)) {
// An empty file name was posted
return false;
} else {
if ($this->exists($name)) {
return false;
}
}
}
$Uploader = new Uploader(array("application/zip"), array(SB_TMP_DIR));
list($result, $tmpfile) = $Uploader->upload($package, SB_TMP_DIR);
if (intval($result) != 1) {
// The file was not uploaded
return false;
}
// handle the file move to the managers dir
if (!FileSystem::make_dir($this->directory . $name)) {
// The target directory could not be created
return false;
}
return $this->unzip($tmpfile, $this->directory . $name);
}
示例6: testUpload
public function testUpload()
{
$connection = new Connection('http://localhost:5984');
$uploader = new Uploader($connection);
$rf = new ResponseFactory();
$get = new GetDocument($rf);
$doc = $get->getDocument($connection, 'test', 'doc');
$uploader->upload('PUT', 'test/' . $doc->_id . '/keya?rev=' . $doc->_rev, 'key');
}
示例7: uploadImage
function uploadImage()
{
$uploader = new \Uploader();
$from = isset($_GET["from"]) ? $_GET["from"] : "default";
$filename = $_GET["filename"];
$info = $uploader->uploadAndPersistImage($filename, "php://input", $from);
header('Content-Type: application/json');
exit(json_encode($info));
}
示例8: createAttachment
public function createAttachment(Uploader $uploader, $database, $id, $revision, $name, $file)
{
$value = $uploader->upload('PUT', $database . '/' . $id . '/' . $name . '?rev=' . $revision, $file);
$response = $this->response_factory->make($value);
if ($response->status() !== '201' && $response->status() !== '202') {
throw new AttachmentCreationException();
}
return json_decode($response->body());
}
示例9: uploadfile
function uploadfile($para)
{
import('image.func');
import('uploader.lib');
$uploader = new Uploader();
$uploader->allowed_type(IMAGE_FILE_TYPE);
$uploader->allowed_size(2097152);
// 2M
$files = $para;
//$_FILES['activity_banner'];
if ($files['error'] == UPLOAD_ERR_OK) {
/* 处理文件上传 */
$file = array('name' => $files['name'], 'type' => $files['type'], 'tmp_name' => $files['tmp_name'], 'size' => $files['size'], 'error' => $files['error']);
$uploader->addFile($file);
if (!$uploader->file_info()) {
$data = current($uploader->get_error());
$res = Lang::get($data['msg']);
$this->view_iframe();
echo "<script type='text/javascript'>alert('{$res}');</script>";
return false;
}
$uploader->root_dir(ROOT_PATH);
$dirname = 'data/files/mall/weixin';
$filename = $uploader->random_filename();
$file_path = $uploader->save($dirname, $filename);
}
return $file_path;
}
示例10: upload
function upload()
{
include_once "classes/Uploader.class.php";
$uploader = new Uploader("image-data");
$uploader->saveIn("img");
$fileUploaded = $uploader->save();
if ($fileUploaded) {
$out = "new file uploaded";
} else {
$out = "something went wrong";
}
return $out;
}
示例11: run
public function run()
{
$uploader = new Uploader();
if (Yii::app()->request->isPostRequest) {
//普通上传
$uploader->initSimple('album')->uploadSimple('simple_file');
$error = $uploader->getError();
if (!$error) {
$data = array('file_name' => $uploader->file_name, 'file_path' => $uploader->file_path, 'file_path_full' => Helper::getFullUrl($uploader->file_path), 'thumb_path' => $uploader->thumb_path, 'thumb_path_full' => Helper::getFullUrl($uploader->thumb_path), 'file_ext' => $uploader->file_ext);
App::response(200, 'success', $data);
} else {
App::response(101, $error);
}
}
}
示例12: actionUpload
/**
* 文件上传
*/
public function actionUpload()
{
$uploader = new Uploader();
if (Yii::app()->request->isPostRequest) {
//断点上传
$uploader->initSimple('kindeditor')->uploadSimple('kindeditor_file');
$error = $uploader->getError();
if (!$error) {
//返回kindeditor接收的json格式
exit(CJSON::encode(array('error' => 0, 'url' => Helper::getFullUrl($uploader->file_path))));
} else {
exit(CJSON::encode(array('error' => 0, 'message' => $error)));
}
}
}
示例13: init
/**
* 初始化函数,并返回当前类
* @return Uploader
*/
public static function init()
{
if (!self::$selfObject) {
self::$selfObject = new Uploader();
}
return self::$selfObject;
}
示例14: actionBatch
/**
* 批量操作
* @throws CHttpException
*/
public function actionBatch()
{
if ($this->method() == 'GET') {
$command = trim($this->_request->getParam('command'));
$ids = intval($this->_request->getParam('id'));
} elseif ($this->method() == 'POST') {
$command = $this->_request->getPost('command');
$ids = $this->_request->getPost('id');
} else {
throw new CHttpException(404, Yii::t('admin', 'Only POST Or GET'));
}
empty($ids) && $this->message('error', Yii::t('admin', 'No Select'));
switch ($command) {
case 'attachDelete':
foreach ((array) $ids as $id) {
$uploadModel = Upload::model()->findByPk($id);
if ($uploadModel) {
Uploader::deleteFile($uploadModel->file_name);
$uploadModel->delete();
}
}
break;
default:
throw new CHttpException(404, Yii::t('admin', 'Error Operation'));
break;
}
$this->message('success', Yii::t('admin', 'Batch Operate Success'), $this->createUrl('index'));
}
示例15: uploadImage
public static function uploadImage()
{
$allowFile = array("image/jpeg", "image/png", "image/gif");
$df = "Ymd-H-i-s";
$fileName = "TMPIMG" . date($df) . "." . Uploader::getExtension();
if (!Uploader::getTempFile()) {
$result['error'] = true;
$result['message'] = 'Please browse for a file!';
echo json_encode($result);
return;
}
if (!in_array(Uploader::getType(), $allowFile)) {
$result['error'] = true;
$result['message'] = 'Please choose only image file (jpg, png or gif)!';
echo json_encode($result);
return;
}
if (Uploader::moveUploadFileTo(self::$tmpDir, $fileName)) {
$result['error'] = false;
$result['message'] = 'File upload succeeded!';
$result['image'] = 'assets/upload/tmp/' . $fileName;
$result['alt'] = $fileName;
} else {
$result['error'] = true;
$result['message'] = 'Fail in moving file upload!';
}
echo json_encode($result);
}