本文讲述了thinkphp3.2实现上传图片的控制器方法。分享给大家供大家参考,具体如下:

public function file()
{
  $baseUrl = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME']));
  import('ORG.Net.UploadFile');
  import('ORG.Util.Services_JSON');
  $upload = new UploadFile();
  $upload->maxSize = 3145728;
  $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg');
  $upload->savePath = './uploads/Images/';
  $info = $upload->uploadOne($_FILES['imgFile']);
  $file_url = $baseUrl . 'uploads/Images/' . $info['0']['savename'];
  if ($info) {
   header('Content-type: text/html; charset=UTF-8');
   $json = new Services_JSON();
   echo $json->encode(array('error' => 0, 'url' => $file_url));
   exit;
  } else {
   $this->error($upload->getErrorMsg());
  }
}
public function file_manager()
{
  import('ORG.Util.Services_JSON');
  $php_path = dirname(__FILE__) . '/';
  $php_url = dirname($_SERVER['PHP_SELF']) . '/';
  $root_path = $php_path . './uploads/Images/';
  $root_url = $php_url . './uploads/Images/';
  $ext_arr = array('gif', 'jpg', 'jpeg', 'png', 'bmp');
  $dir_name = emptyempty($_GET['dir']) "Invalid Directory name.";
   exit;
  }
  if ($dir_name !== '') {
   $root_path .= $dir_name . "/";
   $root_url .= $dir_name . "/";
   if (!file_exists($root_path)) {
    mkdir($root_path);
   }
  }
//根据path参数,设置各路径和URL
  if (emptyempty($_GET['path'])) {
   $current_path = realpath($root_path) . '/';
   $current_url = $root_url;
   $current_dir_path = '';
   $moveup_dir_path = '';
  } else {
   $current_path = realpath($root_path) . '/' . $_GET['path'];
   $current_url = $root_url . $_GET['path'];
   $current_dir_path = $_GET['path'];
   $moveup_dir_path = preg_replace('/(.*"_blank" href="https://www.jb51.net/Special/39.htm">ThinkPHP入门教程》、《ThinkPHP常用方法总结》、《smarty模板入门基础教程》及《PHP模板技术总结》。

希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。

华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com