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.
 
 
 
 

56 lines
2.2 KiB

  1. <?php
  2. /**
  3. * 图片上传
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 倪宗锋
  12. * PhpStorm upload.php
  13. * Create By 2017/3/1 16:23 $
  14. */
  15. if ($_FILES) {
  16. $key = 'oufcisdo3kld50dofdk545645werewre';//秘钥
  17. $rand = $_POST['rand'];
  18. $fileSize = $_FILES['img']['size'];
  19. $token = $_POST['token'];
  20. /**签名校验 秘钥,随机数,图片大小**/
  21. if (md5($key . $rand . $fileSize) != $token) {
  22. echo json_encode(array('flag' => false, 'msg' => 'sign fail!', 'data' => array('file' => $_FILES, 'post' => $_POST)));
  23. die;
  24. }
  25. $filename = $_FILES['img']['name'];
  26. $tmpname = $_FILES['img']['tmp_name'];
  27. $imgUrl = $_POST['fileUrl'];//以/开始
  28. $imgName = $_POST['fileName'];//文件名称
  29. if (is_dir(dirname(__FILE__) . $imgUrl) == false) {
  30. echo json_encode(array('flag' => true, 'msg' => 'dir is not exit!', 'data' => array('file' => $_FILES, 'post' => $_POST)));
  31. }
  32. if (move_uploaded_file($tmpname, dirname(__FILE__) . $imgUrl . $imgName)) {
  33. echo json_encode(array('flag' => true, 'msg' => '', 'data' => array('file' => $_FILES, 'post' => $_POST)));
  34. svnCommit(dirname(__FILE__) . $imgUrl . $imgName);
  35. } else {
  36. echo json_encode(array('flag' => false, 'msg' => 'fail', 'data' => array('file' => $_FILES, 'post' => $_POST)));
  37. }
  38. } else {
  39. echo json_encode(array('flag' => false, 'msg' => 'unRequestFiles', 'data' => array('file' => $_FILES, 'post' => $_POST)));
  40. }
  41. /**
  42. * Des:上传文件更新到svn上
  43. * Name: svnCommit
  44. * @param $file
  45. * @author 倪宗锋
  46. */
  47. function svnCommit($file)
  48. {
  49. $shell = "svn add {$file} --username=nizf --password=nizf --no-auth-cache";
  50. @shell_exec($shell);
  51. $shell = "svn commit {$file} -m 'system' --username=nizf --password=nizf --no-auth-cache";
  52. @shell_exec($shell);
  53. }