php ftp tmp_name,Thinkphp3.2.3FTP上传文件同名覆盖问题

//原代码在\ThinkPHP\Library\Think\Upload\Driver\Ftp.class.php

//大概在94行左右

/**

* 保存指定文件

* @param array $file 保存的文件信息

* @param boolean $replace 同名文件是否覆盖

* @return boolean 保存状态,true-成功,false-失败

*/

public function save($file, $replace=true) {

$filename = $this->rootPath . $file['savepath'] . $file['savename'];

/* 不覆盖同名文件 */

// if (!$replace && is_file($filename)) {

// $this->error = '存在同名文件' . $file['savename'];

// return false;

// }

/* 移动文件 */

if (!ftp_put($this->link, $filename, $file['tmp_name'], FTP_BINARY)) {

$this->error = '文件上传保存错误!';

return false;

}

return true;

}

//源代码当中屏蔽了同名覆盖的判断

//需要改成

//构造函数当中rootPath设置有误

$this->rootPath = ftp_pwd($this->link);

/**

* 保存指定文件

* @param array $file 保存的文件信息

* @param boolean $replace 同名文件是否覆盖

* @return boolean 保存状态,true-成功,false-失败

*/

public function save($file, $replace=true) {

$filename = $this->rootPath . $file['savepath'] . $file['savename'];

/* 不覆盖同名文件 */

if (!$replace) {

ftp_chdir($this->link, $this->rootPath . $file['savepath']);

$ftpFileList = ftp_nlist($this->link, ".");

if(in_array($file['savename'], $ftpFileList)) {

$this->error = '存在同名文件' . $file['savename'];

return false;

}

}

/* 移动文件 */

if (!ftp_put($this->link, $filename, $file['tmp_name'], FTP_BINARY)) {

$this->error = '文件上传保存错误!';

return false;

}

return true;

}

//使用配置config

Array

(

[maxSize] => 734003200

[savePath] =>

[saveName] => test

[exts] => Array

(

[0] => jpeg

[1] => bmp

[2] => zip

[3] => jpg

)

[subName] => 2016/test

[rootPath] =>

)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值