聯(lián)系官方銷售客服
1835022288
028-61286886
m.223987.com的遠(yuǎn)程附件FTP的存儲(chǔ)老是失敗,我修改了一下,終于成功了。對(duì)應(yīng)dayrui\ThirdParty\Storage\Ftp.php文件
<?php namespace Phpcmf\ThirdParty\Storage;
// Ftp文件存儲(chǔ)
class Ftp {
// 存儲(chǔ)內(nèi)容
protected $data;
// 文件存儲(chǔ)路徑
protected $filename;
// 文件存儲(chǔ)目錄
protected $filepath;
// 附件存儲(chǔ)的信息
protected $attachment;
// 是否進(jìn)行圖片水印
protected $watermark;
// 完整的文件目錄
protected $fullpath;
// 完整的文件路徑
protected $fullname;
// 初始化參數(shù)
public function init($attachment, $filename) {
$this->filename = trim($filename, DIRECTORY_SEPARATOR);
$this->filepath = dirname($filename);
$this->filepath == '.' && $this->filepath = '';
$attachment['value']['path'] = rtrim($attachment['value']['path'], DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
$this->attachment = $attachment;
$this->fullpath = $this->attachment['value']['path'].$this->filepath;
$this->fullname = $this->attachment['value']['path'].$this->filename;
return $this;
}
public function makeDir($connect, $dirPath){
//處理目錄
$dirPath = '/' . trim($dirPath, '/');
$dirPath = explode('/', $dirPath);
foreach ($dirPath as $dir) {
if ($dir == '') $dir = '/';
//判斷目錄是否存在
if (@ftp_chdir($connect, $dir) == false) {
//判斷目錄是否創(chuàng)建成功
if (@ftp_mkDir($connect, $dir) == false) {
return 2;
}
@ftp_chdir($connect, $dir);
}
}
return true;
}
// 文件上傳模式
public function upload($type = 0, $data, $watermark) {
$this->data = $data;
$this->watermark = $watermark;
if (!function_exists('ftp_connect')) {
return dr_return_data(0, dr_lang('PHP環(huán)境不支持FTP函數(shù)'));
}
// ftp同步
if (FALSE === ($conn_id = @ftp_connect($this->attachment['value']['host'], $this->attachment['value']['port']))) {
return dr_return_data(0, dr_lang('FTP服務(wù)器連接失敗'));
}
if (@ftp_login($conn_id, $this->attachment['value']['username'], $this->attachment['value']['password']) === FALSE) {
return dr_return_data(0, dr_lang('FTP服務(wù)器賬號(hào)認(rèn)證失敗'));
}
$this->attachment['value']['pasv'] && @ftp_pasv($conn_id, TRUE);
//@ftp_mkdir($conn_id, $this->fullpath);
//@ftp_chmod($conn_id, '0775', $this->fullpath);
if(!$this->makeDir($conn_id, dirname($this->fullname))){
return dr_return_data(0, dr_lang('無法創(chuàng)建FTP目錄'));
}
// 本地臨時(shí)文件
$locpath = WRITEPATH.'attach/'.md5($this->fullname);
// 存儲(chǔ)文件 移動(dòng)上傳或者內(nèi)容存儲(chǔ)
if ($type) {
// 移動(dòng)失敗
if (!(move_uploaded_file($this->data, $locpath) || !is_file($locpath))) {
return dr_return_data(0, dr_lang('文件移動(dòng)失敗'));
}
} else {
$filesize = file_put_contents($locpath, $this->data);
if (!$filesize || !is_file($locpath)) {
return dr_return_data(0, dr_lang('文件創(chuàng)建失敗'));
}
}
if (FALSE === ($result = @ftp_put($conn_id, basename($this->fullname), $locpath, ($this->attachment['value']['mode'] === 'ascii') ? FTP_ASCII : FTP_BINARY))) {
@unlink($locpath);
return dr_return_data(0, dr_lang('FTP服務(wù)器上傳失敗'));
}
@ftp_close($conn_id);
// 強(qiáng)制水印
if ($this->watermark) {
$config = \Phpcmf\Service::C()->get_cache('site', SITE_ID, 'watermark');
$config['source_image'] = $locpath;
$config['dynamic_output'] = false;
\Phpcmf\Service::L('Image')->watermark($config);
}
$md5 = md5_file($locpath);
@unlink($locpath);
// 上傳成功
return dr_return_data(1, 'ok', [
'url' => $this->attachment['url'].$this->filename,
'md5' => $md5,
]);
}
// 刪除文件 這個(gè)我目前不會(huì)寫
public function delete() {
@unlink($this->fullname);
//log_message('info', 'CSRF token verified');
}
}
這是我開發(fā)的插件,兄弟你別公開代碼啊,你讓我怎么生存
回復(fù)@二開/定制/使用解答專家
只有部分核心代碼,還是用不了把?
FTP文件存儲(chǔ)
附件存儲(chǔ)到FTP服務(wù)器中
我用的可以
哈哈,把作者氣死了
是不是不能把文章里的圖片本地化到ftp服務(wù)器上的,這插件,,,,我測(cè)試沒成功,上傳能行,內(nèi)容里圖片本地化,圖片沒法拉到FTP
這個(gè)ftp插件可以實(shí)現(xiàn)本地化呀,我在編輯器里面復(fù)制的文章過來,他就自動(dòng)給我傳到ftp上了
回復(fù)@aohusky
回復(fù)@9龍城 也許是我臉黑,我的遠(yuǎn)程抓取圖片本地化不行,沒法FTP,沒去動(dòng)FTP功能文件,掉坑里了。
很實(shí)用,學(xué)習(xí)一下!?。?/p>