php图文编辑器下载,PHP实现上传和下载文件及thinkPHP引入图文编辑器

一、上传文件:

1、  php.ini配置: 找到 File Uploads

file_uploads = On    //打开上传文件的功能

upload_tmp_dir  =  'd:/web/tmp'   ;   //上传文件的临时存储目录;取决于web服务器部署目录

upload_max_filesize 3M;    //允许上传文件最大值,如若需要较大的值,则需先修改post方式的传输最大值

post_max_size   =8M;

2、  .htaccess 配置

属性和值之间用空格‘  ’隔开非等号‘=’:adddefaultcharset utf-8 //设置默认字符

php_value file_uploads On //打开上传功能

php_value post_max_size 6M // post提交的最大值

php_value upload_max_filesize 6M //允许上传的最大值

(一)上传单个文件:

html 表单:

PHP接受处理上传文件//主要为move_uploaed_file() 的运用

if (!empty($_POST)) {

$dirName = "./".date("Y-m-d");

if (!is_dir($dirName)) {

mkdir($dirName); //如无此目录则创建

}

$suffix = strrchr($_FILES['ufile']['name'], '.');//截取文件的后缀名

$url = $dirName.'/'.uniqid().$suffix; //在日期的目录里以原来的后缀名以唯一性的文件名保存

$bool = move_uploaded_file($_FILES['ufile']['tmp_name'], $url); //从原来的临时文件移动到指定路径

if ($bool) {

echo "上传成功!";

exit();

}else{

echo "上传失败!";

exit();

}

}

(二)上传多个文件:

if(!empty($_POST)){

//创建保存目录

$dirName = "./".date('Y-m-d');

if (!is_dir($dirName)) {

mkdir($dirName);

}

foreach ($_FILES['ufile']['tmp_name'] as $key => $value) {

//取文件后缀 ($key与$_FILES['ufile']['name']数组的key一致)

$suffix = strrchr($_FILES['ufile']['name'][$key],'.');

//生成前缀

$preffix = uniqid();

//保存路径

$url = $dirName."/".$preffix.$suffix;

$bool = move_uploaded_file($value,$url);

}

if ($bool) {

echo "上传成功!";

exit();

}else{

echo "上传失败!";

exit();

}

}

thinkPHP3.2.3 引入编辑器

1、下载 http://kindeditor.net/down.php 压缩包加压到指定目录;

2、引入css及js 加上带id的文本框

图文信息

var editor;

KindEditor.ready(function(K) {

K.create('#ke_c', {

allowFileManager : true

});

});

3、在编辑器压缩包的目录下创建名为attached的目录并修改目录为写入权限;

二、下载文件

A. 当文件为浏览器不能识别的类型时,可直接用a标签实现下载 , 如:下载

B.当文件为浏览器能识别的类型时,即如.html/.js/.css/.xml/.jpg/.jpeg等浏览器能解析直接打开的文件,可用header( ) 及file_get_contents( ) 实现,如:下载$filename = "./load/5b0bd336b7980.jpg";

//提示浏览器为图片文件

header('Content-type: image/jpeg');

//Content-Disposition为内容处理方式,处理为附件,强制浏览器下载文件

header('Content-Disposition: attachment; filename='.$filename);

//将整个文件读入一个字符串,即将二进制对象转为utf-8编码

echo file_get_contents($filename);

常见header( ) 响应头设置://定义编码

header( 'Content-Type:text/html;charset=utf-8 ');

//文档语言

header('Content-language: en');

//CSS

header('Content-type: text/css');

//Javascript

header('Content-type: text/javascript');

//JPEG Image

header('Content-type: image/jpeg');

//XML

header('Content-type: text/xml');

//JSON

header('Content-type: application/json');

//PDF

header('Content-type: application/pdf');

//RSS

header('Content-Type: application/rss+xml; charset=ISO-8859-1');

//Text (Plain)

header('Content-type: text/plain');

//Atom

header('Content-type: application/atom+xml');

//转到一个新地址

header('Location: http://www.example.org/');

// ok

header('HTTP/1.1 200 OK');

//设置一个404头:

header('HTTP/1.1 404 Not Found');

//设置地址被永久的重定向

header('HTTP/1.1 301 Moved Permanently');

//文件延迟转向:

header('Refresh: 10; url=http://www.example.org/');

print 'You will be redirected in 10 seconds';

//当然,也可以使用html语法实现

//

header('Content-Transfer-Encoding: binary');

// load the file to send:

readfile('example.zip');

// 对当前文档禁用缓存

header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');

header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past

header('Pragma: no-cache');

//设置内容类型:

header('Content-Type: text/html; charset=iso-8859-1');

header('Content-Type: text/html; charset=utf-8');

header('Content-Type: text/plain'); //纯文本格式

header('Content-Type: image/jpeg'); //JPG***

header('Content-Type: application/zip'); // ZIP文件

header('Content-Type: application/pdf'); // PDF文件

header('Content-Type: audio/mpeg'); // 音频文件

header('Content-Type: application/x-shockw**e-flash'); //Flash动画

//显示登陆对话框

header('HTTP/1.1 401 Unauthorized');

header('WWW-Authenticate: Basic realm="Top Secret"');

print 'Text that will be displayed if the user hits cancel or ';

print 'enters wrong login data';//下载xlsx文件

$filename = rtrim($_SERVER['DOCUMENT_ROOT'],'/').'/app/files/payment_status.csv';

header('Content-Disposition: attachment; filename=payment_status.xlsx');

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');

header('Content-Length: ' . filesize($filename));

header('Content-Transfer-Encoding: binary');

header('Cache-Control: must-revalidate');

header('Pragma: public');

readfile($filename);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值