uchome安装插件怎么安装

当前位置: >
uchome头像上传插件的使用
时间: 17:02&&&&来源:学吧网&&&&点击:&&&&
今日,有个项目中要用到头像上传。开始想用jquery插件jcrop.js来实现的,但是又想偷懒,就放弃了。想想uchome里有头像上传的功能的,就直接拿过来用了。过程也很简单,就跟大家分享交流下吧。【】
第一步:将camera.swf【上传插件】和locale.xml【配置文件】拷贝到项目中来,存放位置自己定额。将crossdomain.xml【缺少它,会出现跨域无法上传的错误】拷贝到根目录下。
第二步:在页面中引入插件。我这里以一个demo文件为例。
&html xmlns="http://www.w3.org/1999/xhtml"&
&meta http-equiv="Content-Type" content="text/ charset=utf-8" /&
&title&头像上传&/title&
&object classid="clsid:d27cdb6e-ae6d-11cf-96b8-" codebase="/
pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="447" height="477" id="mycamera"
align="middle"&
¶m name="allowScriptAccess" value="always" /&
¶m name="scale" value="exactfit" /&
¶m name="wmode" value="transparent" /&
¶m name="quality" value="high" /&
¶m name="bgcolor" value="#ffffff" /&
&!--域名:http://test--&
&!--项目ID:appid【可以根据修改成用户ID等】--&
&!--处理页面:http://test/camera/upload.php--&
¶m name="movie" value="http://test/canera/camera.swf?inajax=1&appid=1&input=576ewKr7hvoOkGa6
DU8Q8NtyAbWc31n6EDjvudMMH1eMhYc8l9CvDkObulKWnqNHB0aZ%2BO4XWWYmKGthbzlJ0tWFUB6pGHbaKpq67PTAvuEC3tyA
A%2BnGZhgaCWO6Vg&agent=8b4131bad188afe8dc4f2c291c7b89d9&ucapi=http://test/camera/upload.php" /&
¶m name="menu" value="false" /&
&!--配置跟上面的一样--&
&!--至于宽高等 ,直接修改width,hright即可--&
&embed src="http://test/camera/camera.swf?inajax=1&appid=1&input=576ewKr7hvoOkGa6DU8Q8NtyAbWc31n6
EDjvudMMH1eMhYc8l9CvDkObulKWnqNHB0aZ%2BO4XWWYmKGthbzlJ0tWFUB6pGHbaKpq67PTAvuEC3tyAA%2BnGZhgaCWO6Vg
&agent=8b4131bad188afe8dc4f2c291c7b89d9&ucapi=http://test/camera/upload.php" quality="high"
bgcolor="#ffffff" width="460" height="300" name="mycamera" align="middle" allowScriptAccess="always"
allowFullScreen="false" scale="exactfit"
wmode="transparent" type="application/x-shockwave-flash"
&pluginspage="/go/getflashplayer" /&
第三步:PHP页面处理上传结果。
* 处理头像上传
define('UPLOAD_PATH',
'./upload/');
//定义上传文件目录
define('WEB_URL',
'http://test/camera/');
//定义网站URL
if (isset($_REQUEST['Filename'])) {
echo upload();
echo save();
* 上传头像
function upload() {
@header("Expires: 0");
@header("Cache-Control: private, post-check=0, pre-check=0, max-age=0", FALSE);
@header("Pragma: no-cache");
$uid = $_REQUEST['appid'];
if(empty($uid)) {
return -1;
if(empty($_FILES['Filedata'])) {
return -3;
list($width, $height, $type, $attr) = getimagesize($_FILES['Filedata']['tmp_name']);
$imgtype = array(1 =& '.gif', 2 =& '.jpg', 3 =& '.png');
$filetype = $imgtype[$type];
if(!$filetype) {
$filetype = '.jpg';
$dir = UPLOAD_PATH . '/tmp/';
if (!is_dir($dir)) {
mkdir($dir, 0775);
$tmpavatar = $dir . $uid . $
file_exists($tmpavatar) && @unlink($tmpavatar);
if(@copy($_FILES['Filedata']['tmp_name'], $tmpavatar) ||
@move_uploaded_file($_FILES['Filedata']['tmp_name'], $tmpavatar)) {
@unlink($_FILES['Filedata']['tmp_name']);
list($width, $height, $type, $attr) = getimagesize($tmpavatar);
if($width & 10 || $height & 10 || $type == 4) {
@unlink($tmpavatar);
return -2;
@unlink($_FILES['Filedata']['tmp_name']);
return -4;
$avatarurl = WEB_URL . basename(UPLOAD_PATH) . '/tmp/' . $uid . $
* 保存头像
function save() {
@header("Expires: 0");
@header("Cache-Control: private, post-check=0, pre-check=0, max-age=0", FALSE);
@header("Pragma: no-cache");
header("Content-type: application/ charset=utf-8");
$uid = $_REQUEST['appid'];
if(empty($uid)) {
return '&root&&message type="error" value="-1" /&&/root&';
$dir = UPLOAD_PATH . '/user/';
if (!is_dir($dir)) {
mkdir($dir, 0775);
$bigavatarfile = $dir . $uid . '_big.jpg';
$bigavatar = flashdata_decode($_REQUEST['avatar1']);
$midavatarfile = $dir . $uid . '_mid.jpg';
$midavatar = flashdata_decode($_REQUEST['avatar2']);
$smallavatarfile = $dir . $uid . '_sma.jpg';
$smallavatar = flashdata_decode($_REQUEST['avatar3']);
$success = 1;
$fp = @fopen($bigavatarfile, 'wb');
@fwrite($fp, $bigavatar);
@fclose($fp);
$fp = @fopen($midavatarfile, 'wb');
@fwrite($fp, $midavatar);
@fclose($fp);
$fp = @fopen($smallavatarfile, 'wb');
@fwrite($fp, $smallavatar);
@fclose($fp);
$info1 = @getimagesize($bigavatarfile);
$info2 = @getimagesize($midavatarfile);
$info3 = @getimagesize($smallavatarfile);
if(!$info1 || $info1[2] == 4 || !$info2 || $info2[2] == 4 || !$info3 || $info3[2] == 4) {
file_exists($bigavatarfile) && unlink($bigavatarfile);
file_exists($midavatarfile) && unlink($midavatarfile);
file_exists($smallavatarfile) && unlink($smallavatarfile);
$success = 0;
//删除原图
$filename = UPLOAD_PATH . '/tmp/' . $uid . '.jpg';
file_exists($filename) && @unlink($filename);
$filename = UPLOAD_PATH . '/tmp/' . $uid . '.png';
file_exists($filename) && @unlink($filename);
$filename = UPLOAD_PATH . '/tmp/' . $uid . '.gif';
file_exists($filename) && @unlink($filename);
if($success) {
return '&?xml version="1.0" ?&&root&&face success="1"/&&/root&';
return '&?xml version="1.0" ?&&root&&face success="0"/&&/root&';
function flashdata_decode($s) {
$l = strlen($s);
for($i=0; $i&$l; $i=$i+2) {
$k1 = ord($s[$i]) - 48;
$k1 -= $k1 & 9 ? 7 : 0;
$k2 = ord($s[$i+1]) - 48;
$k2 -= $k2 & 9 ? 7 : 0;
$r .= chr($k1 && 4 | $k2);
return $r;
使用这个插件还是挺快捷方便的,就是一些参数不能修改,比较难受。比如上传的图片不能大于1M等等。各有利弊吧,看大家的选择了。

参考资料

 

随机推荐