?> "></a> <a onclick="return attachInsertEditor(this)" href="/<?php echo $attach['path']; ?> ">插入文章</a> <a onclick="return setCoverPic(this);" href="<?php echo $attach['path']; ?> ">设为封面</a> <a onclick="return attachInsertEditor(this);" href="/<?php echo cc_get_img_path($attach['path'], 'thumb'); ?> ">插入缩略图</a> <a onclick="return setCoverPic(this);" href="<?php echo cc_get_img_path($attach['path'], 'thumb'); ?> ">封面缩略图</a> <a onclick="return deleteAttach(this);" href="<?php echo $attach['id']; ?> ">删除</a> </li> <?php } ?> <?php } ?> </ul>
public function ajaxUpload() { $data = array(); $success = 0; $message = ''; $data['result'] = array(); if ($this->input->post('post', TRUE) > 0) { //附件目录 $pathDir = $this->backend_lib->getUploadDir('attach'); //上传文件类配置 $config = array(); $config['upload_path'] = "./{$pathDir}/"; $config['allowed_types'] = 'gif|jpg|jpeg|jpe|png'; $config['max_size'] = '2048'; $config['max_width'] = '3000'; $config['max_height'] = '3000'; $config['remove_spaces'] = TRUE; $config['encrypt_name'] = TRUE; $this->upload->initialize($config); if (!$this->upload->do_upload()) { $message = $this->upload->display_errors(); } else { //上传完成的数组 $uploadData = $this->upload->data(); //图片路径 $imgPath = $uploadData['full_path']; //获取图片大小 $imgSize = getimagesize($imgPath); //宽度 $imgWidth = $imgSize[0]; $imgHeight = $imgSize[1]; $width = $this->backend_lib->getSetting('attach_thumb_width'); $height = $this->backend_lib->getSetting('attach_thumb_height'); $quality = $this->backend_lib->getSetting('attach_quality'); //宽度最小 if ($imgWidth < $width) { $width = $imgWidth; } //生成缩略图 $this->backend_lib->createImg($imgPath, $width, $height, '_thumb', $quality); //写入数据库 $param = array('name' => $uploadData['file_name'], 'orig_name' => $uploadData['orig_name'], 'path' => $pathDir . $uploadData['file_name'], 'type' => $uploadData['image_type']); $this->attach_model->save($param); $attachId = $this->db->insert_id(); if ($attachId) { $success = 1; $message = '上传成功'; $data['attachId'] = $attachId; $data['result'] = $uploadData; $data['picUrl'] = $pathDir . $uploadData['file_name']; $data['picUrlThumb'] = $pathDir . cc_get_img_path($uploadData['file_name'], 'thumb'); } else { $message = '上传失败'; } } } else { $message = 'none'; } $data['success'] = $success; $data['message'] = $message; echo json_encode($data); }