123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- // Work-around for setting up a session because Flash Player doesn't send the cookies
- if (isset($_POST["PHPSESSID"])) {
- session_id($_POST["PHPSESSID"]);
- }
- session_start();
- $path = "../editor/ueditor/php/upload/".date("Ymd")."/";
- if(isset($_POST["base64"]) && $_POST["base64"]){
- if(!is_dir($path)){
- mkdir($path);
- }
- $arr = explode("??????????",$_POST["base64"]);
-
- $resultArr = array();
- for($i=0;$i<count($arr);$i++){
- $tmp = base64_decode($arr[$i]);
- $filename = $_POST["baseUpIndex"]."fz".time().$i.".png";
- file_put_contents($path.$filename, $tmp);
-
- array_push($resultArr,array(
- "code" => "200",
- "filename" => $filename,
- "msg" => "文件保存成功!",
- "pathname" => date("Ymd")."/".$filename,
- ));
- }
- echo json_encode($resultArr);
- }
- else if (preg_match("/(\.jpg|\.png|\.gif|^blob)$/",$_FILES["Filedata"]["name"]) && $_FILES["Filedata"]["size"] < 100*1024*1024){
- if ($_FILES["Filedata"]["error"] > 0) {
- echo '{"code":"500","msg":"上传出错:'.$_FILES["Filedata"]["error"].'"}';
- }else {
- $result=1;
- if (file_exists($path . $_FILES["Filedata"]["name"])){
- $result=unlink ($path . $_FILES["Filedata"]["name"]);
- }
- if (isset($_POST["filename"]) && $_POST["filename"] && file_exists($path . $_POST["filename"])){
- $result=unlink ($path . $_POST["filename"]);
- }
- if($result){
- if(!is_dir($path)){
- mkdir($path);
- }
- preg_match("/(\.jpg|\.png|\.gif)$/",$_FILES["Filedata"]["name"],$hz);
- if($_FILES["Filedata"]["name"]=="blob"){
- $hz[0] = ".png";
- }
- $filename = "fz".time().$hz[0];
- $result = move_uploaded_file($_FILES["Filedata"]["tmp_name"], $path . $filename);
- echo '{"code":"200","filename":"'.$filename.'","msg":"文件保存成功!","pathname":"'.date("Ymd")."/".$filename.'"}';
- }else{
- echo '{"code":"500","msg":"上传出错"}';
- }
- }
-
- }else {
- echo '{"code":"500","msg":"文件不符合格式"}';
- }
- exit(0);
- ?>
|