上传头像怎么保存图片?
程序员文章站
2024-02-08 23:59:48
...
index.php
========================================
function create_password($pw_length = 8)
{
$randpwd = '';
for ($i = 0; $i {
$randpwd .= chr(mt_rand(33, 126));
}
return $randpwd;
}
?>
sdcms.cn.php
===============================
/*
*仿新浪微博上传头像功能
*联系QQ:631897379
*演示:http://www.16934.net/demo
*png1,png2,png3分别为3个尺寸头像的参数,经过base64解密后保存即可
*/
$filename120 = "1_120.jpg";
$filename48 = "1_48.jpg";
$filename24 = "1_24.jpg";
$somecontent1=base64_decode($_POST['png1']);
$somecontent2=base64_decode($_POST['png2']);
$somecontent3=base64_decode($_POST['png3']);
if($handle=fopen($filename120,"w+"))
{
if(!fwrite($handle,$somecontent1)==FALSE)
{
fclose($handle);
}
}
if($handle=fopen($filename48,"w+"))
{
if(!fwrite($handle,$somecontent2)==FALSE)
{
fclose($handle);
}
}
if($handle=fopen($filename24,"w+"))
{
if(!fwrite($handle,$somecontent3)==FALSE)
{
fclose($handle);
}
}
echo "success=上传成功";
?>
========================================
Flash头像上传组件效果预览
function create_password($pw_length = 8)
{
$randpwd = '';
for ($i = 0; $i {
$randpwd .= chr(mt_rand(33, 126));
}
return $randpwd;
}
?>
sdcms.cn.php
===============================
/*
*仿新浪微博上传头像功能
*联系QQ:631897379
*演示:http://www.16934.net/demo
*png1,png2,png3分别为3个尺寸头像的参数,经过base64解密后保存即可
*/
$filename120 = "1_120.jpg";
$filename48 = "1_48.jpg";
$filename24 = "1_24.jpg";
$somecontent1=base64_decode($_POST['png1']);
$somecontent2=base64_decode($_POST['png2']);
$somecontent3=base64_decode($_POST['png3']);
if($handle=fopen($filename120,"w+"))
{
if(!fwrite($handle,$somecontent1)==FALSE)
{
fclose($handle);
}
}
if($handle=fopen($filename48,"w+"))
{
if(!fwrite($handle,$somecontent2)==FALSE)
{
fclose($handle);
}
}
if($handle=fopen($filename24,"w+"))
{
if(!fwrite($handle,$somecontent3)==FALSE)
{
fclose($handle);
}
}
echo "success=上传成功";
?>
回复讨论(解决方案)
你的$_FILES呢?
去看手册: $_FILES 你就明白了
上一篇: thinkphp中怎么办上传文件