zblog
当前位置:首页 > 商学院 > zblog > 正文内容

zblog

从文件夹中随机获取一张图片上传到附件并删除

豫唐网络2022-12-17 10:231916

本方案采用的是php语言,操作步骤如下:

1、从文件夹中随机抽取一张图片

$url=$zbp->path."imgs/";
$img_array=glob($url."*.jpg",GLOB_BRACE);
$num=array_rand($img_array);
$filename=$img_array[$num];
echo$filename;

2、制作转移函数

functiontc_imgssize_getSaveFileDir($times,$fileName)
{
global$zbp;
$fileDirPath=$zbp->usersdir.'upload/'.date('Y',$times).'/'.date('m',$times);
if(!file_exists($fileDirPath)){
@mkdir($fileDirPath,0755,true);
}
return$fileDirPath."/".$fileName;
}

3、上传到附件

$va1=str_replace($url,"",$fileName);
$vc=explode('.',$va1);
$suffix=$vc[1];
$size=filesize($fileName);
$times=time();//固定时间
$fileName=date("YmdHis",$times).$times.rand(10000,99999).'.'.$suffix;
$fileSavePath=tc_imgssize_getSaveFileDir($times,$fileName);
$upload=new\Upload();
$upload->Name=$fileName;
$upload->SourceName=$fileName;
$upload->MimeType="image/".$suffix;
$upload->Size=$size;
$upload->AuthorID=1;
rename($va,$fileSavePath);
$filepath=$fileSavePath;
$upload->Save();

4、获取新的图片地址

$imgurl=$zbp->host.'zb_users/upload/'.date('Y',$times).'/'.date('m',$times)."/".$fileName;
echo$imgurl;


扫描二维码推送至手机访问。

版权声明:本文由汤阴县豫唐网络科技有限公司发布,如需转载请注明出处。

本文链接:https://www.ytecn.com/post/464.html

分享给朋友:

相关文章

向字符串型的参数列表加入一个新参数

向字符串型的参数列表加入一个新参数

可以使用zblog PHP的AddNameInString 函数。AddNameInString 函数向字符串型的参数列表加入一个新参数。ZBP中有很多地方的选项值采用了如a|b|c这样的字符串来存储...

zblogphp页面管理页面增加子菜单接口说明

zblogphp页面管理页面增加子菜单接口说明

接口名称:Filter_Plugin_Admin_PageMng_SubMenu接口描述:文章管理页面增加子菜单调用方法:Add_Filter_Plugin('Filter_Plugin_Ad...

zblogphp文章页面编辑页开始接口说明

zblogphp文章页面编辑页开始接口说明

接口名称:Filter_Plugin_Edit_Begin接口描述:文章编辑页加载前处理内容。应用场景:可直接跳转到其他页面,处理自身业务流程。调用方法:Add_Filter_Plugin('...

zblogphp文章页面编辑页结束接口说明

zblogphp文章页面编辑页结束接口说明

接口名称:Filter_Plugin_Edit_End接口描述:文章编辑页加载前处理内容。应用场景:可直接跳转到其他页面,处理自身业务流程。调用方法:Add_Filter_Plugin('Fi...

zba文件怎么使用?zba文件是什么?

zba文件怎么使用?zba文件是什么?

.zba是zblogphp的专用应用格式。应用格式又分主题和插件两种。.zba主题安装,打开zblog后台,选择《主题管理》,点击《本地上传并安装主题zba文件》,上传后点击提交,然后开启主题,安装完...

zblogphp数据字典zblogphp数据库字典zblogphp数据表字段大全

zblogphp数据字典zblogphp数据库字典zblogphp数据表字段大全

zblogphp系统默认为8张表,分别为category(分类表)、comment(评论表)、config(系统和应用配置表)、member(用户表)、module(模块表)、post(文章表(含...