聯系官方銷售客服
1835022288
028-61286886
www.zbshanke.com的遠程附件FTP的存儲老是失敗,我修改了一下,終于成功了。對應dayrui\ThirdParty\Storage\Ftp.php文件
<?php namespace Phpcmf\ThirdParty\Storage;
// Ftp文件存儲
class Ftp {
// 存儲內容
protected $data;
// 文件存儲路徑
protected $filename;
// 文件存儲目錄
protected $filepath;
// 附件存儲的信息
protected $attachment;
// 是否進行圖片水印
protected $watermark;
// 完整的文件目錄
protected $fullpath;
// 完整的文件路徑
protected $fullname;
// 初始化參數
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) {
//判斷目錄是否創建成功
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環境不支持FTP函數'));
}
// ftp同步
if (FALSE === ($conn_id = @ftp_connect($this->attachment['value']['host'], $this->attachment['value']['port']))) {
return dr_return_data(0, dr_lang('FTP服務器連接失敗'));
}
if (@ftp_login($conn_id, $this->attachment['value']['username'], $this->attachment['value']['password']) === FALSE) {
return dr_return_data(0, dr_lang('FTP服務器賬號認證失敗'));
}
$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('無法創建FTP目錄'));
}
// 本地臨時文件
$locpath = WRITEPATH.'attach/'.md5($this->fullname);
// 存儲文件 移動上傳或者內容存儲
if ($type) {
// 移動失敗
if (!(move_uploaded_file($this->data, $locpath) || !is_file($locpath))) {
return dr_return_data(0, dr_lang('文件移動失敗'));
}
} else {
$filesize = file_put_contents($locpath, $this->data);
if (!$filesize || !is_file($locpath)) {
return dr_return_data(0, dr_lang('文件創建失敗'));
}
}
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服務器上傳失敗'));
}
@ftp_close($conn_id);
// 強制水印
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,
]);
}
// 刪除文件 這個我目前不會寫
public function delete() {
@unlink($this->fullname);
//log_message('info', 'CSRF token verified');
}
}
這是我開發的插件,兄弟你別公開代碼啊,你讓我怎么生存
回復@二開/定制/使用解答專家
只有部分核心代碼,還是用不了把?
FTP文件存儲
附件存儲到FTP服務器中
我用的可以
哈哈,把作者氣死了
是不是不能把文章里的圖片本地化到ftp服務器上的,這插件,,,,我測試沒成功,上傳能行,內容里圖片本地化,圖片沒法拉到FTP
這個ftp插件可以實現本地化呀,我在編輯器里面復制的文章過來,他就自動給我傳到ftp上了
回復@aohusky
回復@9龍城 也許是我臉黑,我的遠程抓取圖片本地化不行,沒法FTP,沒去動FTP功能文件,掉坑里了。
很實用,學習一下!!!