uploadImg.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. // Work-around for setting up a session because Flash Player doesn't send the cookies
  3. if (isset($_POST["PHPSESSID"])) {
  4. session_id($_POST["PHPSESSID"]);
  5. }
  6. session_start();
  7. $path = "../editor/ueditor/php/upload/".date("Ymd")."/";
  8. if(isset($_POST["base64"]) && $_POST["base64"]){
  9. if(!is_dir($path)){
  10. mkdir($path);
  11. }
  12. $arr = explode("??????????",$_POST["base64"]);
  13. $resultArr = array();
  14. for($i=0;$i<count($arr);$i++){
  15. $tmp = base64_decode($arr[$i]);
  16. $filename = $_POST["baseUpIndex"]."fz".time().$i.".png";
  17. file_put_contents($path.$filename, $tmp);
  18. array_push($resultArr,array(
  19. "code" => "200",
  20. "filename" => $filename,
  21. "msg" => "文件保存成功!",
  22. "pathname" => date("Ymd")."/".$filename,
  23. ));
  24. }
  25. echo json_encode($resultArr);
  26. }
  27. else if (preg_match("/(\.jpg|\.png|\.gif|^blob)$/",$_FILES["Filedata"]["name"]) && $_FILES["Filedata"]["size"] < 100*1024*1024){
  28. if ($_FILES["Filedata"]["error"] > 0) {
  29. echo '{"code":"500","msg":"上传出错:'.$_FILES["Filedata"]["error"].'"}';
  30. }else {
  31. $result=1;
  32. if (file_exists($path . $_FILES["Filedata"]["name"])){
  33. $result=unlink ($path . $_FILES["Filedata"]["name"]);
  34. }
  35. if (isset($_POST["filename"]) && $_POST["filename"] && file_exists($path . $_POST["filename"])){
  36. $result=unlink ($path . $_POST["filename"]);
  37. }
  38. if($result){
  39. if(!is_dir($path)){
  40. mkdir($path);
  41. }
  42. preg_match("/(\.jpg|\.png|\.gif)$/",$_FILES["Filedata"]["name"],$hz);
  43. if($_FILES["Filedata"]["name"]=="blob"){
  44. $hz[0] = ".png";
  45. }
  46. $filename = "fz".time().$hz[0];
  47. $result = move_uploaded_file($_FILES["Filedata"]["tmp_name"], $path . $filename);
  48. echo '{"code":"200","filename":"'.$filename.'","msg":"文件保存成功!","pathname":"'.date("Ymd")."/".$filename.'"}';
  49. }else{
  50. echo '{"code":"500","msg":"上传出错"}';
  51. }
  52. }
  53. }else {
  54. echo '{"code":"500","msg":"文件不符合格式"}';
  55. }
  56. exit(0);
  57. ?>