`

琐碎的学习——上传文件到又拍云

阅读更多

利用又拍云存储官方php的sdk,我们可以在自己的网站上简单实现上传文件到又拍云。

 

示例网页

 

<html>
	<head>upload to upyun</head>
	<body>
		<div id="res">  
			<form enctype="multipart/form-data" action="upyun.php" method="POST">
				Send this file to upyun:
				<input name="file" id="file" type="file" />
				<input name="submit" type="submit" value="Send File" />
				<label id="fullPath" />
			</form>
		</div>
	</body>
</html>

下载php的sdk,编写upyun.php如下:

 

<?php

$file_name = $_FILES["file"]["name"];
$tmp_file = $_FILES["file"]["tmp_name"];


require_once('upyun.class.php');
/// 初始化空间
$upyun = new UpYun("myspace", "myname", "mypwd");

/// 切换 API 接口的域名
/// {默认 v0.api.upyun.com 自动识别, v1.api.upyun.com 电信, v2.api.upyun.com 联通, v3.api.upyun.com 移动}
$upyun->setApiDomain('v0.api.upyun.com');


$fh = fopen($tmp_file,'r'); var_dump($upyun->writeFile("/".$file_name, $fh)); fclose($fh);

/// 读取目录
//var_dump($upyun->readDir('/'));

Header("Location: ".$_SERVER["HTTP_REFERER"]);

 这样,上传到本服务器的文件直接通过api接口上传到又拍云。(需要配置myspace为文件空间而不是图片空间)

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics