博客已转移,最新地址请点击:flash上传
做项目的很多情况要用到flash头像上传,但是网上好像很难找,而自己也不会用flash做。今天就给大家分享一个.在最下面会分享源码
首先在需要的地方加入以下代码:
< style type = "text/css" media = "screen" > html, body { height:100%; background-color: #ffffff;} #flashContent { width:100%; height:100%; } </ style > < script type = "text/javascript" > function uploadevent(status){ //alert(status); status += ''; switch(status){ case '1': var time = new Date().getTime(); document.getElementById('avatar_priview').innerHTML = "头像1 : < img src = '1.png?" + time + "' /> < br /> 头像2: < img src = '2.png?" + time + "' />< br /> 头像3: < img src = '3.png?" + time + "' />" ; break; break; case '-1': window.location.reload(); break; default: window.location.reload(); } } </ script > </ head > < body > < div id = "altContent" > < OBJECT classid = "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase = "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" WIDTH = "650" HEIGHT = "450" id = "myMovieName" > < PARAM NAME = movie VALUE = "avatar.swf" > < PARAM NAME = quality VALUE = high > < PARAM NAME = bgcolor VALUE=#FFFFFF> < param name = "flashvars" value = "imgUrl=./default.jpg&uploadUrl=./upfile.php&uploadSrc=false" /> < EMBED src = "avatar.swf" quality = high bgcolor=#FFFFFF WIDTH = "650" HEIGHT = "450" wmode = "transparent" //头像上传用到的swf文件,注意地址 flashVars = "imgUrl=./default.jpg&uploadUrl=./upfile.php&uploadSrc=false" 提交到的PHP文件地址 NAME = "myMovieName" ALIGN = "" TYPE = "application/x-shockwave-flash" allowScriptAccess = "always" PLUGINSPAGE = "http://www.macromedia.com/go/getflashplayer" > </ EMBED > </ OBJECT > </ div > < div id = "avatar_priview" ></ div > |
修改对了以后看一下upfile.php文件
<?php $file_src = "src.png" ; $filename162 = time(). "1.png" ; //不同尺寸的图片保存的名称 $filename48 = time(). "2.png" ; $filename20 = time(). "3.png" ; $filepath = './uploads/' ; //保存地址 if (! file_exists ( $filepath )){ mkdir ( './uploads' ); } $base64_decode ( $_POST [ 'pic' ]); $pic1 = base64_decode ( $_POST [ 'pic1' ]); $pic2 = base64_decode ( $_POST [ 'pic2' ]); $pic3 = base64_decode ( $_POST [ 'pic3' ]); if ( $src ) { file_put_contents ( $file_src , $src ); } file_put_contents ( $filename162 , $pic1 ); file_put_contents ( $filename48 , $pic2 ); file_put_contents ( $filename20 , $pic3 ); $rs [ 'status' ] = 1; print json_encode( $rs ); ?> |
自己根据需要再加一些安全的判断,这个是我从网上找的一个flash,还不错然后修改的,不过有一些地方要改的话需要懂flash,我也不会,所以如果有熟悉的朋友的话也希望帮帮忙。前面加代码的地方里,可以把提交的地址改掉,只要最后地址不要弄错了就可以了。如果有其他的问题可以加群:252799167一起讨论