本文整理汇总了PHP中UploadFile::FTPuplode方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadFile::FTPuplode方法的具体用法?PHP UploadFile::FTPuplode怎么用?PHP UploadFile::FTPuplode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UploadFile
的用法示例。
在下文中一共展示了UploadFile::FTPuplode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: uploadavatar
/**
* 上传头像
*/
public function uploadavatar()
{
$auth_data = authcode($_GET['auth_data'], "DECODE");
if ($auth_data != AppframeAction::$Cache['uid']) {
exit("0");
}
if (isset($GLOBALS['HTTP_RAW_POST_DATA'])) {
//flashpost
$avatardata = $GLOBALS['HTTP_RAW_POST_DATA'];
}
$dir = C("UPLOADFILEPATH") . "/avatar/" . AppframeAction::$Cache['uid'] . '/';
//创建图片存储文件夹
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
//存储flashpost图片压缩包 member/avatar/用户id/
$filename = $dir . AppframeAction::$Cache['uid'] . ".zip";
file_put_contents($filename, $avatardata);
import("Pclzip");
$archive = new PclZip($filename);
if ($archive->extract(PCLZIP_OPT_PATH, $dir) == 0) {
die("Error : " . $archive->errorInfo(true));
}
//判断文件安全,删除压缩包和非jpg图片
$avatararr = array('180x180.jpg', '30x30.jpg', '45x45.jpg', '90x90.jpg');
if (defined("CONFIG_FTPSTATUS") && CONFIG_FTPSTATUS) {
import("UploadFile");
import("Dir");
$Dir = new Dir();
$UploadFile = new UploadFile();
}
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file !== '.' && $file !== '..') {
if (!in_array($file, $avatararr)) {
@unlink($dir . $file);
} else {
$info = @getimagesize($dir . $file);
if (!$info || $info[2] != 2) {
@unlink($dir . $file);
}
}
if (defined("CONFIG_FTPSTATUS") && CONFIG_FTPSTATUS) {
//如果有开启FTP,则上传到FTP上
$UploadFile->FTPuplode($dir . $file, $dir . $file);
}
}
}
closedir($handle);
}
//如果是上传FTP,删除
if (defined("CONFIG_FTPSTATUS") && CONFIG_FTPSTATUS) {
$Dir->delDir($dir);
}
//保存头像地址到数据库,默认保存90x90.jpg
//20121214 废除,userpic用于保存非本地头像,例如QQ登陆后的第三方头像。
//M("Member")->where(array("userid" => AppframeAction::$Cache['uid']))->save(array("userpic" => "avatar/" . AppframeAction::$Cache['uid'] . '/90x90.jpg'));
exit('1');
}
示例2: download
/**
* 远程保存
* @param $value 传入下载内容
* @param $watermark 是否加入水印
* @param $ext 下载扩展名
*/
public function download($value, $watermark = '', $ext = 'gif|jpg|jpeg|bmp|png')
{
//检查是否有开启CURL
if (!function_exists('curl_init')) {
return $value;
}
if ($watermark == '') {
if ($this->Config['watermarkenable']) {
$watermark = true;
}
}
$curl = curl_init();
//正则匹配是否有符合数据
if (!preg_match_all("/(href|src)=([\"|']?)([^ \"'>]+\\.({$ext}))\\2/i", $value, $matches)) {
return $value;
}
$remotefileurls = array();
//过滤域名
$NoDomain = explode("|", CONFIG_FILEEXCLUDE);
//当前程序所在域名地址
$NoDomain[] = urlDomain(get_url());
//附件地址
$upload_url = urlDomain(CONFIG_SITEFILEURL);
foreach ($matches[3] as $matche) {
//过滤远程地址
if (strpos($matche, '://') === false) {
continue;
}
//过滤后台设置的域名,和本站域名
if (in_array(urlDomain($matche), $NoDomain)) {
continue;
}
$remotefileurls[] = $matche;
}
//保存目录
$FilePath = $this->FilePath();
$oldpath = $newpath = array();
import('UploadFile');
$upload = new UploadFile();
foreach ($remotefileurls as $k => $file) {
if (strpos($file, '://') === false || strpos($file, $upload_url) !== false) {
continue;
}
//取得文件扩展
$file_fileext = fileext($file);
//取得文件名
$file_name = basename($file);
//保存文件名
$filename = uniqid() . "." . $file_fileext;
// 设置你需要抓取的URL
curl_setopt($curl, CURLOPT_URL, $file);
// 设置header
curl_setopt($curl, CURLOPT_HEADER, 0);
// 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//超时设置
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
// 运行cURL,请求网页
$filedata = curl_exec($curl);
//保存图片
$status = $this->build_file($filedata, $FilePath . "/" . $filename);
if ($status) {
//加水印
if ($watermark) {
$this->water($FilePath . "/" . $filename, "", $FilePath . "/" . $filename);
}
$oldpath[] = $file;
$newpath[] = str_replace($this->path, CONFIG_SITEFILEURL, $FilePath . "/" . $filename);
$info = array("name" => $file_name, "type" => "", "size" => filesize($FilePath . "/" . $filename), "key" => "", "extension" => $file_fileext, "savepath" => $FilePath, "savename" => "/" . $filename, "hash" => md5(str_replace($this->path, "", $FilePath . "/" . $filename)));
$aid = $this->FileData($info);
//设置标识
$this->upload_json($aid, $this->filehttp, $filename);
//FTP
if ($this->Ftpstatus) {
// 远程存放地址
$remote = $this->Config['ftpuppat'] . str_replace(SITE_PATH . "/", "", $FilePath . "/" . $filename);
if ($upload->FTPuplode($FilePath . "/" . $filename, $remote)) {
//删除
unlink($FilePath . "/" . $filename);
}
}
}
}
// 关闭URL请求
curl_close($curl);
$value = str_replace($oldpath, $newpath, $value);
return $value;
}