PHP高级上传图片时,提示move_uploaded_file错误/chomd函数查看了下,原来服务器禁用了chmod()函数 上传文件连读的权限都没有 解除禁用后还是报这个错误,还是上传转移文件的问题,最后解决了原来是服务器空间不足了,导致转移失败,,,真是太无语了 以下附源码 上传类 上传方法 public function upload() { //解决部分浏览器swfupload新建线程的问题 if (!empty($_POST[作者王明昌发布时间2018-06-29最后更新2018-06-29查看了下,原来服务器禁用了chmod()函数 上传文件连读的权限都没有解除禁用后还是报这个错误,还是上传转移文件的问题,最后解决了原来是服务器空间不足了,导致转移失败,,,真是太无语了以下附源码上传类复制savePath = $savePath; $this->allowExts = $allowExts; $this->maxSize = $maxSize; if( class_exists('SaeStorage') ) { $this->saeStorage = new SaeStorage(); } } public function upload($key='') { if( empty($_FILES) ) { $this->errorMsg = '没有文件上传!'; return false; } if( empty($key) ) { $files = $_FILES; } else { $files[$key] = $_FILES[$key]; } $num = 0; foreach($files as $key =>$file) { if( $file['error'] == 4 ) continue; $saveRuleFunc = $this->saveRule; $pathinfo = pathinfo($file['name']); $file['key'] = $key; $file['extension'] = strtolower( $pathinfo['extension'] ); $file['savepath'] = $this->savePath; $file['savename'] = $saveRuleFunc( $file['tmp_name'] ) . '.' . $file['extension']; //检查文件类型大小和合法性 if ( !$this->check($file) ) { return false; } //存储文件 if ( $this->autoSave ) { if( isset($this->saeStorage) ) { $file['savepath'] = str_replace(array('../', './'), '', $file['savepath']); $ret = $this->saeSave($file['tmp_name'], $file['savepath'] . $file['savename']); } else { $ret = $this->localSave($file['tmp_name'], $file['savepath'] . $file['savename']); } if( !$ret ) { return false; } $this->thumb($file); //缩略图片 } $this->uploadFileInfo[$key] = $file; $this->uploadFileInfo[$num++] = $file; } return true; } //检查文件类型大小和合法性 protected function check($file) { //文件上传失败 if($file['error'] !== 0) { $this->errorMsg= '文件上传失败!'; return false; } //检查文件类型 $this->allowExts = array_map('strtolower', $this->allowExts); if( !in_array($file['extension'], $this->allowExts) ) { $this->errorMsg = '上传文件类型不允许!'; return false; } //检查文件大小 if ( $file['size'] > $this->maxSize ) { $this->errorMsg = '上传文件大小超出限制!'; return false; } //检查是否合法上传 if(!is_uploaded_file($file['tmp_name'])) { $this->errorMsg = '非法上传文件!'; return false; } // 如果是图像文件 检测文件格式 if( in_array($file['extension'], array('gif','jpg','jpeg','bmp','png','swf')) && false === getimagesize($file['tmp_name']) ) { $this->errorMsg = '非法图像文件'; return false; } //检查通过,返回true return true; } //缩略图片 protected function thumb($file) { if ($this->thumb && in_array($file['extension'], array('gif', 'jpg', 'jpeg', 'bmp', 'png')) ) { $this->thumbPath = $this->thumbPath ? $this->thumbPath : $file['savepath']; $thumbname = $this->thumbPath . $this->thumbPrefix . basename($file['savename']); require_once(dirname(__FILE__).'/Image.class.php'); $imagename = isset($this->saeStorage) ? $file['tmp_name'] : $file['savepath'] . $file['savename']; return Image::thumb($imagename, $thumbname, $this->domain, $this->thumbMaxWidth, $this->thumbMaxHeight); // 生成图像缩略图 } return false; } //sae存储 protected function saeSave($srcFileName, $destFileName) { if ( false!= $this->saeStorage->upload($this->domain, $destFileName, $srcFileName) ) { return true; } else { $this->errorMsg = $this->saeStorage->errmsg(); return false; } } //本地存储 protected function localSave($srcFileName, $destFileName) { $dir = dirname($destFileName); if ( !is_dir($dir) ) { if ( !mkdir($dir, 0777, true) ) { $this->errorMsg = '上传目录' . $dir . '不存在'; return false; } } else { if ( !is_writeable($dir) ) { $this->errorMsg = '上传目录' . $dir . '不可写'; return false; } } echo "复制"; var_dump($srcFileName);die; if( move_uploaded_file($srcFileName, $destFileName) ) { return true; } $this->errorMsg= '文件上传保存错误!'; return false; } //上传成功获取返回信息 public function getUploadFileInfo() { return $this->uploadFileInfo; } //获取错误信息 public function getErrorMsg() { return $this->errorMsg; } } ?> 上传方法 复制public function upload() { //解决部分浏览器swfupload新建线程的问题 if (!empty($_POST['PHPSESSID'])) { session_id(in($_POST['PHPSESSID'])); session_start(); } $upload_dir = $_SESSION['formtoken']; $upload = new UploadFile(); //设置上传文件大小 $upload->maxSize = 1024 * 1024 * 20; //最大2M //定义允许上传的文件扩展名 $ext_arr = array( 'image' => array('gif', 'jpg', 'jpeg', 'png', 'bmp'), 'flash' => array('swf', 'flv'), 'media' => array('swf', 'flv', 'mp4', 'wav', 'wma', 'wmv', 'mid', 'avi', 'mpg', 'asf', 'rm', 'rmvb'), 'file' => array('doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'pdf', 'zip', 'rar', '7z'), ); //设置上传文件类型 $dir_name = empty($_GET['dir']) ? 'image' : in($_GET['dir']); if ($dir_name == 'image') { $upload->thumb = false; //开启缩略图 $upload->thumbMaxWidth = 120; $upload->thumbMaxHeight = 90; } $upload->allowExts = $ext_arr[$dir_name]; //设置附件上传目录 $upload->savePath = $this->config['site_attached']. $upload_dir . '/' . $dir_name . '/'; $upload->saveRule = cp_uniqid; @chmod($upload->savePath, 0777); //设置权限 if (!$upload->upload()) { //捕获上传异常 echo json_encode(array('error' => 1, 'message' => $upload->getErrorMsg())); } else { //取得成功上传的文件信息 $fileinfo = $upload->getUploadFileInfo(); echo json_encode(array("error" => 0, "url" => __ROOT__ . '/' . $upload->savePath . $fileinfo['imgFile']['savename'])); } }
2018-08-22支付宝支付接口错误说明错误查询 https://docs.open.alipay.com/58/103599/ 今天我遇到的一个错误,经过询问小二,网关错误,错误如下 ILLEGAL_ACCESS_SWITCH_SYSTE
2019-12-10阿里巴巴开源镜像提供的 packagist 镜像服务全局配置(推荐) 所有项目都会使用该镜像地址: composer config -g repo.packagist composer https://mirrors.aliyun.com/compos
2018-08-26实例 | 支付宝支付(使用md5加密)参数的获取 pid|key获取: 商户中心---账户管理---查看pid|key https://openhome.alipay.com/platform/keyManage.htm?keyType=
2018-10-31实例 | tp5使用七牛云上传图片和文件/删除文件thinkphp5中使用七牛云 下载 https://github.com/qiniu/php-sdk vendor文件下 新建文件 application/extra/qiniu.php retur
2018-07-04转载 | ThinkPHP5+Layui实现图片上传加预览 图片 上传图片 layui.use('upload',function(){ var upload = layui.upload, jq = layui.jquery; upload.render
2018-05-28ajax-post传值的写法var data = {type:type,is_ok:is_ok,id:id}; $("#train").on("click",function(){ var id = $("#id_res").v