upload.php 907 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. //公用上传程序
  3. //@author yuanjiang Date. 8.23.2013
  4. define('IN_T',true);
  5. require 'include/init.php';;
  6. $act = Common::sfilter($_REQUEST['act']);
  7. /* 未登录 */
  8. if($admin['id']<=0){
  9. echo $Json->encode(array('error'=>1,'message'=>'请先登录!'));
  10. exit;
  11. }
  12. /* 未上传文件 */
  13. if(empty($_FILES))
  14. {
  15. echo $Json->encode(array('error'=>1,'message'=>'非法请求!'));
  16. exit;
  17. }
  18. $old = getcwd(); //当前目录
  19. chdir(ROOT_PATH); //切换到程序根目录
  20. //文章详情
  21. if($act=='article'){
  22. $dir_path = 'data/article/'.date('Ym',Common::gmtime());
  23. Common::make_dir($dir_path);
  24. $file_path = $dir_path.'/'.Common::gmtime().'.png';
  25. $data['error'] = 1;
  26. if(move_uploaded_file($_FILES['imgFile']['tmp_name'],$file_path)){
  27. $data = array('error'=>0,'url'=>'/'.$file_path);
  28. }
  29. else{
  30. $data['message'] = '上传失败!';
  31. }
  32. }
  33. chdir($old);
  34. echo $Json->encode($data);
  35. exit;
  36. ?>