1

嘿伙计们,我的脚本在这里应该做一些事情然后删除一个文件,不幸的是我的文件永远不会取消链接。我想知道这可能是什么原因?权限是我唯一能想到的,或者输出缓冲区可能搞砸了?我真的不知道,但希望得到一些关于如何处理它的建议。问题有问题的是最后一个 IF() 块。

public function remoteFtp() {
    $enabled = Mage::getStoreConfig('cataloginventory/settings/use_ftp');
    $remove = Mage::getStoreConfig('cataloginventory/settings/ftp_remove_file');
    if ($enabled == 0) {
        return true;
    }

    $base_path = Mage::getBaseDir('base');


    $ftp_url = Mage::getStoreConfig('cataloginventory/settings/ftp_url');
    $ftp_user = Mage::getStoreConfig('cataloginventory/settings/ftp_user');
    $ftp_pass = Mage::getStoreConfig('cataloginventory/settings/ftp_password');
    $ftp_remote_dir = Mage::getStoreConfig('cataloginventory/settings/ftp_remote_dir');
    $ftp_filename_filter = Mage::getStoreConfig('cataloginventory/settings/ftp_remote_filename');

    $ftp_file = $base_path . '/edi/working/working.edi';

    $handle = fopen($ftp_file, 'w');
    $conn_id = ftp_connect($ftp_url);

    ftp_login($conn_id, $ftp_user, $ftp_pass) or die("unable to login");

    if ($ftp_remote_dir) {
        ftp_chdir($conn_id, $ftp_remote_dir);
    }

    //is there a file
    $remote_list = ftp_nlist($conn_id, ".");

    $exists = count($remote_list);

    if ($exists > 0) {
        $len = strlen($ftp_filename_filter) - 1;


        foreach ($remote_list as $name) {
            if (substr($ftp_filename_filter, 0, 1) == "*") {

                if (substr($name, '-' . $len) == substr($ftp_filename_filter, '-' . $len)) {
                    $ftp_remote_name = $name;
                }
            }
            if (substr($ftp_filename_filter, strlen($name) - 1) == "*") {
                if (substr($ftp_filename_filter, 0, $len) == substr($name, 0, $len)) {
                    $ftp_remote_name = $name;
                }
            }
            if ($ftp_filename_filter == $name) {
                $ftp_remote_name = $name;
            }
        }
    }


    if (ftp_fget($conn_id, $handle, $ftp_remote_name, FTP_ASCII, 0)) {
        echo "successfully written to $ftp_file <br />";
        if ($remove == 1) {
            ftp_delete($conn_id, $ftp_remote_name);
        }
    } else {
        echo "There was a problem while downloading $ftp_remote_name to $ftp_file <br />";
    }

    ftp_close($conn_id);
}
4

1 回答 1

2

答案是系统变量$remove = Mage::getStoreConfig('cataloginventory/settings/ftp_remove_file');设置为 BOOL(false)

于 2012-04-12T17:59:00.100 回答