You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.1 KiB
60 lines
2.1 KiB
<?php
|
|
require 'config.php';
|
|
if(!$enable) die("{'url':'',state:'没有涂鸦权限'}"); //权限验证
|
|
//上传配置
|
|
$config = array(
|
|
"savePath" => $root_path_relative . IMAGE_DIR . '/upload/', //存储文件夹
|
|
"maxSize" => 1000 , //允许的文件最大尺寸,单位KB
|
|
"allowFiles" => array( ".gif" , ".png" , ".jpg" , ".jpeg" , ".bmp" ) //允许的文件格式
|
|
);
|
|
//临时文件目录
|
|
$tmpPath = "tmp/";
|
|
//获取当前上传的类型
|
|
$action = htmlspecialchars( $_GET[ "action" ] );
|
|
if ( $action == "tmpImg" ) { // 背景上传
|
|
//背景保存在临时目录中
|
|
$config[ "savePath" ] = $tmpPath;
|
|
$up = new Uploader( "upfile" , $config );
|
|
$info = $up->getFileInfo();
|
|
/**
|
|
* 返回数据,调用父页面的ue_callback回调
|
|
*/
|
|
echo "<script>parent.ue_callback('" . $info[ "url" ] . "','" . $info[ "state" ] . "')</script>";
|
|
} else {
|
|
//涂鸦上传,上传方式采用了base64编码模式,所以第三个参数设置为true
|
|
$up = new Uploader( "content" , $config , true );
|
|
//上传成功后删除临时目录
|
|
if(file_exists($tmpPath)){
|
|
delDir($tmpPath);
|
|
}
|
|
$info = $up->getFileInfo();
|
|
//处理文件路径
|
|
$info["url"] = str_replace($root_path_relative, $root_path, $info["url"]);
|
|
echo "{'url':'" . $info[ "url" ] . "',state:'" . $info[ "state" ] . "'}";
|
|
}
|
|
/**
|
|
* 删除整个目录
|
|
* @param $dir
|
|
* @return bool
|
|
*/
|
|
function delDir( $dir )
|
|
{
|
|
//先删除目录下的所有文件:
|
|
$dh = opendir( $dir );
|
|
while ( $file = readdir( $dh ) ) {
|
|
if ( $file != "." && $file != ".." ) {
|
|
$fullpath = $dir . "/" . $file;
|
|
if ( !is_dir( $fullpath ) ) {
|
|
unlink( $fullpath );
|
|
} else {
|
|
delDir( $fullpath );
|
|
}
|
|
}
|
|
}
|
|
closedir( $dh );
|
|
//删除当前文件夹:
|
|
return rmdir( $dir );
|
|
}
|
|
|
|
|
|
|
|
|