NoteOnMe博客平台搭建
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 line
1.1 KiB

3 年之前
  1. <?php
  2. /**
  3. * 图片上传处理
  4. * User: CorwienWong
  5. * Date: 16-06-15
  6. * Time: 00:33
  7. */
  8. header("Content-type:text/html;charset=utf-8");
  9. // 配置文件需要上传到服务器的路径,需要允许所有用户有可写权限,否则无法上传成功
  10. $uploadPath = 'image/';
  11. // 获取提交的图片数据
  12. $file = $_FILES['opus'];
  13. // 获取图片回调路径
  14. $callbackUrl = $_POST['callbackUrl'];
  15. if($file['error'] > 0)
  16. {
  17. $msg = '传入参数错误' . $file['error'] . " ";
  18. exit($msg);
  19. }
  20. else
  21. {
  22. // chmod($uploadPath, 0666);
  23. if(file_exists($uploadPath.$file['name'])){
  24. $msg = $file['name'] . "文件已经存在!";
  25. exit($msg);
  26. }
  27. else
  28. {
  29. if(move_uploaded_file($file['tmp_name'], $uploadPath.$file['name']))
  30. {
  31. $img_url = "http://localhost/app/".$uploadPath.$file['name'];
  32. $img_url = urlencode($img_url);
  33. $url = $callbackUrl."?img_url={$img_url}";
  34. // 跳转
  35. header("location:{$url}");
  36. return;
  37. }
  38. else
  39. {
  40. exit("上传失败!");
  41. }
  42. }
  43. }