爱程序网

uploadify实现七牛云存储 显示上传进度+页面显示

来源: 阅读:

准备:

uploadify下载地址:

http://www.uploadify.com/download/

七牛 php-sdk开发指南:

http://developer.qiniu.com/docs/v6/sdk/php-sdk.html

php-sdk地址:

https://github.com/qiniu/php-sdk

开始:

 DEMO:

http://hxend.com/uploadif/

 

在七牛里面注册账号以后,成为标准用户

免费存储空间10GB
免费每月下载流量10GB
免费每月PUT/DELETE 10万次请求
免费每月GET 100万次请求

貌似是一个不错的福利。

成功注册后就会 账号页面 有ak 和sk key 可以在代码中使用。

下载好uploadify 后 把 七牛 php -sdk 文件包里面的内容放在 uploadify 里面

打开uploadify.php 文件  代码如下:

<?php/*UploadifyCopyright (c) 2012 Reactive Apps, Ronnie GarciaReleased under the MIT License <http://www.opensource.org/licenses/mit-license.php> */// Define a destination$targetFolder = '/uploads'; // Relative to the root$verifyToken = md5('unique_salt' . $_POST['timestamp']);if (!empty($_FILES) && $_POST['token'] == $verifyToken) {	$tempFile = $_FILES['Filedata']['tmp_name'];	$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;	$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];		// Validate the file type	$fileTypes = array('jpg','jpeg','gif','png'); // File extensions	$fileParts = pathinfo($_FILES['Filedata']['name']);		if (in_array($fileParts['extension'],$fileTypes)) {		move_uploaded_file($tempFile,$targetFile);		echo '1';	} else {		echo 'Invalid file type.';	}}?>

相关文章列表: