|
- <?php
- /**
- * 图片上传
- * ============================================================================
- * * 版权所有 蜘蛛出行 * *
- * 网站地址: http://www.zhizhuchuxing.com
- * ----------------------------------------------------------------------------
- * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
- * 使用;不允许对程序代码以任何形式任何目的的再发布。
- * ============================================================================
- * Author By: 倪宗锋
- * PhpStorm upload.php
- * Create By 2017/3/1 16:23 $
- */
- if ($_FILES) {
- $key = 'oufcisdo3kld50dofdk545645werewre';//秘钥
- $rand = $_POST['rand'];
- $fileSize = $_FILES['img']['size'];
- $token = $_POST['token'];
- /**签名校验 秘钥,随机数,图片大小**/
- if (md5($key . $rand . $fileSize) != $token) {
- echo json_encode(array('flag' => false, 'msg' => 'sign fail!', 'data' => array('file' => $_FILES, 'post' => $_POST)));
- die;
- }
- $filename = $_FILES['img']['name'];
- $tmpname = $_FILES['img']['tmp_name'];
- $imgUrl = $_POST['fileUrl'];//以/开始
- $imgName = $_POST['fileName'];//文件名称
- if (is_dir(dirname(__FILE__) . $imgUrl) == false) {
- echo json_encode(array('flag' => true, 'msg' => 'dir is not exit!', 'data' => array('file' => $_FILES, 'post' => $_POST)));
-
- }
- if (move_uploaded_file($tmpname, dirname(__FILE__) . $imgUrl . $imgName)) {
- echo json_encode(array('flag' => true, 'msg' => '', 'data' => array('file' => $_FILES, 'post' => $_POST)));
- svnCommit(dirname(__FILE__) . $imgUrl . $imgName);
- } else {
- echo json_encode(array('flag' => false, 'msg' => 'fail', 'data' => array('file' => $_FILES, 'post' => $_POST)));
- }
- } else {
- echo json_encode(array('flag' => false, 'msg' => 'unRequestFiles', 'data' => array('file' => $_FILES, 'post' => $_POST)));
- }
- /**
- * Des:上传文件更新到svn上
- * Name: svnCommit
- * @param $file
- * @author 倪宗锋
- */
- function svnCommit($file)
- {
- $shell = "svn add {$file} --username=nizf --password=nizf --no-auth-cache";
- @shell_exec($shell);
- $shell = "svn commit {$file} -m 'system' --username=nizf --password=nizf --no-auth-cache";
- @shell_exec($shell);
-
- }
|