public function do_handle() { /* 抓取远程图片 */ $list = array(); if (isset($_POST[$this->fieldName])) { $source = $_POST[$this->fieldName]; } else { $source = $_GET[$this->fieldName]; } foreach ($source as $imgUrl) { $item = new Uploader($imgUrl, $this->config, "remote"); $info = $item->getFileInfo(); array_push($list, array("state" => $info["state"], "url" => $info["url"], "size" => $info["size"], "title" => htmlspecialchars($info["title"]), "original" => htmlspecialchars($info["original"]), "source" => htmlspecialchars($imgUrl))); } /* 返回抓取数据 */ return json_encode(array('state' => count($list) ? 'SUCCESS' : 'ERROR', 'list' => $list)); }
public function imgUpload() { Vendor('um.Uploader', '', '.class.php'); $config = array("savePath" => APP_PATH . "Public/Upload/", "maxSize" => 2 * 1024, "allowFiles" => array(".gif", ".png", ".jpg", ".jpeg", ".bmp")); $up = new Uploader("upfile", $config); $type = $_REQUEST['type']; $callback = $_GET['callback']; $info = $up->getFileInfo(); $info['url'] = str_replace(APP_PATH, '', $info['url']); /** * 返回数据 */ if ($callback) { echo '<script>' . $callback . '(' . json_encode($info) . ')</script>'; } else { echo json_encode($info); } }
<?php header("Content-Type:text/html;charset=utf-8"); error_reporting(E_ERROR | E_WARNING); date_default_timezone_set("Asia/chongqing"); include "Uploader.class.php"; //上传配置 $config = array("savePath" => "../../upload/", "maxSize" => 10000, "allowFiles" => array(".gif", ".png", ".jpg", ".jpeg", ".bmp")); //上传文件目录 $Path = "upload/"; //背景保存在临时目录中 $config["savePath"] = $Path; $up = new Uploader("upfile", $config); $type = $_REQUEST['type']; $callback = $_GET['callback']; $info = $up->getFileInfo(); /** * 返回数据 */ if ($callback) { echo '<script>' . $callback . '(' . json_encode($info) . ')</script>'; } else { echo json_encode($info); }
case 'uploadscrawl': $config = array("pathFormat" => $CONFIG['scrawlPathFormat'], "maxSize" => $CONFIG['scrawlMaxSize'], "allowFiles" => $CONFIG['scrawlAllowFiles'], "oriName" => "scrawl.png"); $fieldName = $CONFIG['scrawlFieldName']; $base64 = "base64"; break; case 'uploadvideo': $config = array("pathFormat" => $CONFIG['videoPathFormat'], "maxSize" => $CONFIG['videoMaxSize'], "allowFiles" => $CONFIG['videoAllowFiles']); $fieldName = $CONFIG['videoFieldName']; break; case 'uploadfile': default: $config = array("pathFormat" => $CONFIG['filePathFormat'], "maxSize" => $CONFIG['fileMaxSize'], "allowFiles" => $CONFIG['fileAllowFiles']); $fieldName = $CONFIG['fileFieldName']; break; } /* 生成上传实例对象并完成上传 */ $up = new Uploader($fieldName, $config, $base64); /** * 得到上传文件所对应的各个参数,数组结构 * array( * "state" => "", //上传状态,上传成功时必须返回"SUCCESS" * "url" => "", //返回的地址 * "title" => "", //新文件名 * "original" => "", //原始文件名 * "type" => "" //文件类型 * "size" => "", //文件大小 * ) */ /* 返回数据 */ return json_encode($up->getFileInfo());
<?php /** * 抓取远程图片 * User: Jinqn * Date: 14-04-14 * Time: 下午19:18 */ set_time_limit(0); include "Uploader.class.php"; /* 上传配置 */ $config = array("pathFormat" => $CONFIG['catcherPathFormat'], "maxSize" => $CONFIG['catcherMaxSize'], "allowFiles" => $CONFIG['catcherAllowFiles'], "oriName" => "remote.png"); $fieldName = $CONFIG['catcherFieldName']; /* 抓取远程图片 */ $list = array(); if (isset($_POST[$fieldName])) { $source = $_POST[$fieldName]; } else { $source = $_GET[$fieldName]; } foreach ($source as $imgUrl) { $item = new Uploader($imgUrl, $config, "remote"); $info = $item->getFileInfo(); array_push($list, array("state" => $info["state"], "url" => $info["url"], "source" => $imgUrl)); } /* 返回抓取数据 */ return json_encode(array('state' => count($list) ? 'SUCCESS' : 'ERROR', 'list' => $list));
break; case 'uploadvideo': $config = array("pathFormat" => "/customers/{$cus_name}/images/ueditor/{time}{rand:6}", "maxSize" => $CONFIG['videoMaxSize'], "allowFiles" => $CONFIG['videoAllowFiles']); $fieldName = $CONFIG['videoFieldName']; break; case 'uploadfile': default: $config = array("pathFormat" => "/customers/{$cus_name}/images/ueditor/{time}{rand:6}", "maxSize" => $CONFIG['fileMaxSize'], "allowFiles" => $CONFIG['fileAllowFiles']); $fieldName = $CONFIG['fileFieldName']; break; } //$test=array('sta',1); //return json_encode($test); /* 生成上传实例对象并完成上传 */ $up = new Uploader($fieldName, $config, $base64); $up_result = $up->getFileInfo(); /* 同步到客户服务器 */ if ($up_result['state'] == 'SUCCESS') { //同步到客户服务器 $customerinfo = Customer::find($cus_id); $ftp_array = explode(':', $customerinfo->ftp_address); $ftp_array[1] = isset($ftp_array[1]) ? $ftp_array[1] : '21'; $conn = ftp_connect($ftp_array[0], $ftp_array[1]); if ($conn) { ftp_login($conn, $customerinfo->ftp_user, $customerinfo->ftp_pwd); /* 编辑器上传图片问题 */ ftp_pasv($conn, 1); //===扣除空间=== // customers/$cus_name/images/ueditor/ // $size = filesize(public_path('customers/' . $cus_name . '/images/ueditor/' . $up_result['title'])); // $reg=ueditor_regular(1024);
public function _crawler($CONFIG) { /** * 抓取远程图片 * User: Jinqn * Date: 14-04-14 * Time: 下午19:18 */ set_time_limit(0); // include("Uploader.class.php"); /* 上传配置 */ $config = array("pathFormat" => $CONFIG['catcherPathFormat'], "maxSize" => $CONFIG['catcherMaxSize'], "allowFiles" => $CONFIG['catcherAllowFiles'], "oriName" => "remote.png"); $fieldName = $CONFIG['catcherFieldName']; /* 抓取远程图片 */ $list = array(); if (isset($_POST[$fieldName])) { $source = $_POST[$fieldName]; } else { $source = $_GET[$fieldName]; } foreach ($source as $imgUrl) { $item = new Uploader($imgUrl, $config, "remote"); $info = $item->getFileInfo(); array_push($list, array("state" => $info["state"], "url" => $info["url"], "size" => $info["size"], "title" => htmlspecialchars($info["title"]), "original" => htmlspecialchars($info["original"]), "source" => htmlspecialchars($imgUrl))); } /* 返回抓取数据 */ return json_encode(array('state' => count($list) ? 'SUCCESS' : 'ERROR', 'list' => $list)); }
/** * 各种上传 * @param $fieldName * @param $config * @param $base64 */ protected function upload($fieldName, $config, $base64 = 'upload') { $up = new Uploader($fieldName, $config, $base64); $info = $up->getFileInfo(); if ($this->thumbnail && $info['state'] == 'SUCCESS' && in_array($info['type'], array('.png', '.jpg', '.bmp', '.gif'))) { $info['thumbnail'] = $this->imageHandle($info['url']); } $info['url'] = Yii::app()->params['main_site'] . $info['url']; $result = json_encode($info); $this->show($result); }
<?php include "Uploader.class.php"; $CONFIG = json_decode(preg_replace("/\\/\\*[\\s\\S]+?\\*\\//", "", file_get_contents("config.json")), true); #config $config = array("pathFormat" => $CONFIG['imagePathFormat'], "maxSize" => $CONFIG['imageMaxSize'], "allowFiles" => $CONFIG['imageAllowFiles']); $fieldName = "upload"; $base64 = "upload"; #这里要对$_File进行处理 $size = @$_GET["size"]; $json = array(); $temp_array = $_FILES; for ($i = 0; $i < $size; $i++) { $name = @$temp_array[$fieldName]["name"][$i]; $type = @$temp_array[$fieldName]["type"][$i]; $tmp_name = @$temp_array[$fieldName]["tmp_name"][$i]; $error = @$temp_array[$fieldName]["error"][$i]; $sizez = @$temp_array[$fieldName]["size"][$i]; $_FILES = array(); $_FILES[$fieldName]["name"] = $name; $_FILES[$fieldName]["type"] = $type; $_FILES[$fieldName]["tmp_name"] = $tmp_name; $_FILES[$fieldName]["error"] = $error; $_FILES[$fieldName]["size"] = $sizez; #config change $up = new Uploader($fieldName, $config, $base64); $res = $up->getFileInfo(); $json[] = $res; } #echo echo json_encode($json);
public function do_handle() { $up = new Uploader($this->fieldName, $this->config, $this->base64); return json_encode($up->getFileInfo()); }
/** * 文件处理服务 * @param string $Root,string $cmd,string $target * @return array */ public function mfile($ROOT, $cmd, $target) { switch ($cmd) { case 'init': return getArray('0', 'success', array('root' => getFileInfo('/', $ROOT), 'config' => array())); break; case 'ls': if (isset($_GET['target'])) { $target = $_GET['target']; } else { $target = ''; } $list = listFile($target, $ROOT); return getArray('0', 'success', array('files' => $list)); break; case 'rename': $name = $_GET['name']; if (file_exists($ROOT . $name)) { $res = false; $msg = 'file exist'; } else { $res = rename($ROOT . $target, $ROOT . $name); } if ($res) { return getArray('0', 'success', array('file' => getFileInfo($name, $ROOT))); } else { return getArray('1', $msg ? $msg : 'rename error'); } break; case 'rm': foreach ($target as $key => $path) { if (is_dir($ROOT . $path)) { $res = removeDir($ROOT . $path); } else { $res = unlink($ROOT . $path); } if (!$res) { break; } } if ($res) { return getArray('0', 'success'); } else { return getArray('1', 'romove error'); } break; case 'touch': if (!file_exists($ROOT . $target)) { file_put_contents($ROOT . $target, ''); $res = file_exists($ROOT . $target); } else { $res = false; $msg = 'file exist'; } if ($res) { return getArray('0', 'success', array('file' => getFileInfo($target, $ROOT))); } else { return getArray('1', $msg ? $msg : 'touch error'); } break; case 'mkdir': if (!file_exists($ROOT . $target)) { $res = mkdir($ROOT . $target); } else { $res = false; $msg = 'file exist'; } if ($res) { return getArray('0', 'success', array('file' => getFileInfo($target, $ROOT))); } else { return getArray('1', $msg ? $msg : 'mkdir error', array('file' => getFileInfo($target, $ROOT))); } break; case 'upload': include "Uploader.class.php"; $uploadConfig = array("savePath" => $ROOT . $target, "maxSize" => 200000, "allowFiles" => array(".rar", ".zip", ".7z", "tar", "gz", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", "", ".txt", ".pdf", ".bmp", ".gif", ".jpg", ".jpeg", ".png", ".psd", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg", ".ogg", ".mov", ".wmv", ".mp4", ".webm")); $up = new Uploader("file", $uploadConfig); $info = $up->getFileInfo(); if ($info["state"] == 'SUCCESS') { return getArray('0', 'success', array('file' => getFileInfo($target . $info["name"], $ROOT))); } else { return getArray('1', $info["state"], array('file' => getFileInfo($target . $info["name"], $ROOT))); } break; case 'download': $path = $ROOT . $target; $info = getFileInfo($target, $ROOT); downloadFile($path, $info['name']); break; case 'info': return getArray('0', 'success', array('file' => getFileInfo($target, $ROOT))); break; default: return getArray('1', 'unknow command'); break; } /*switch*/ }
case 'uploadscrawl': $config = array("pathFormat" => $CONFIG['scrawlPathFormat'], "maxSize" => $CONFIG['scrawlMaxSize'], "allowFiles" => $CONFIG['scrawlAllowFiles'], "oriName" => "scrawl.png"); $fieldName = $CONFIG['scrawlFieldName']; $base64 = "base64"; break; case 'uploadvideo': $config = array("pathFormat" => $CONFIG['videoPathFormat'], "maxSize" => $CONFIG['videoMaxSize'], "allowFiles" => $CONFIG['videoAllowFiles']); $fieldName = $CONFIG['videoFieldName']; break; case 'uploadfile': default: $config = array("pathFormat" => $CONFIG['filePathFormat'], "maxSize" => $CONFIG['fileMaxSize'], "allowFiles" => $CONFIG['fileAllowFiles']); $fieldName = $CONFIG['fileFieldName']; break; } /* 生成上传实例对象并完成上传 */ $up = new Uploader($fieldName, $config, $base64); /** * 得到上传文件所对应的各个参数,数组结构 * array( * "state" => "", //上传状态,上传成功时必须返回"SUCCESS" * "url" => "", //返回的地址 * "title" => "", //新文件名 * "original" => "", //原始文件名 * "type" => "" //文件类型 * "size" => "", //文件大小 * ) */ /* 返回数据 */ return json_encode($up->getFileInfo('http://m2.nadoo.cn/p/zyw'));
private function crawler() { set_time_limit(0); /* 上传配置 */ $config = array("pathFormat" => $this->conf['catcherPathFormat'], "maxSize" => $this->conf['catcherMaxSize'], "allowFiles" => $this->conf['catcherAllowFiles'], "oriName" => "remote.png"); $fieldName = $this->conf['catcherFieldName']; /* 抓取远程图片 */ $list = array(); if (isset($_POST[$fieldName])) { $source = $_POST[$fieldName]; } else { $source = $_GET[$fieldName]; } foreach ($source as $imgUrl) { $item = new Uploader($imgUrl, $config, "remote"); $info = $item->getFileInfo(); array_push($list, array("state" => $info["state"], "url" => $info["url"], "size" => $info["size"], "title" => htmlspecialchars($info["title"]), "original" => htmlspecialchars($info["original"]), "source" => htmlspecialchars($imgUrl))); } /* 返回抓取数据 */ return json_encode(array('state' => count($list) ? 'SUCCESS' : 'ERROR', 'list' => $list)); }
case 'uploadscrawl': $config = array("pathFormat" => $CONFIG['scrawlPathFormat'], "maxSize" => $CONFIG['scrawlMaxSize'], "allowFiles" => $CONFIG['scrawlAllowFiles'], "oriName" => "scrawl.png"); $fieldName = $CONFIG['scrawlFieldName']; $base64 = "base64"; break; case 'uploadvideo': $config = array("pathFormat" => $CONFIG['videoPathFormat'], "maxSize" => $CONFIG['videoMaxSize'], "allowFiles" => $CONFIG['videoAllowFiles']); $fieldName = $CONFIG['videoFieldName']; break; case 'uploadfile': default: $config = array("pathFormat" => $CONFIG['filePathFormat'], "maxSize" => $CONFIG['fileMaxSize'], "allowFiles" => $CONFIG['fileAllowFiles']); $fieldName = $CONFIG['fileFieldName']; break; } /* 生成上传实例对象并完成上传 */ $up = new Uploader($fieldName, $config, $base64); /** * 得到上传文件所对应的各个参数,数组结构 * array( * "state" => "", //上传状态,上传成功时必须返回"SUCCESS" * "url" => "", //返回的地址 * "title" => "", //新文件名 * "original" => "", //原始文件名 * "type" => "" //文件类型 * "size" => "", //文件大小 * ) */ /* 返回数据 */ return json_encode($up->getFileInfo('http://admin.yggx.net'));