【问题标题】:PHP ftp_put replacing a file from a dev site to a live sitePHP ftp_put 将文件从开发站点替换为实时站点
【发布时间】:2015-12-09 17:56:08
【问题描述】:

我只是想用 ftp 替换一个文件,两个目的地都在同一个服务器上

新文件:/home/srv/dev_html/test.php
旧文件:/home/srv/public_html/test.php

$new = "/home/srv/dev_html/test.php";
$old = "/home/srv/public_html/test.php";

$tmp = explode("/",$new);
$newfile = end($tmp);
$newdir = str_replace($newfile,"",$new);

ftp_chdir($conn_id,$newdir); //try changing directory

ftp_put($conn_id, $old, $newfile, FTP_ASCII);

ftp_chdir 发生错误,提示
ftp_chdir(): Can't change directory to /home/srv/dev_html/: No such file or directory

我已使用 file_exists() 确认它存在。
这是否意味着您不能使用绝对路径?
如果不是,还有什么更好的方法?

谢谢

【问题讨论】:

    标签: php file ftp directory


    【解决方案1】:

    改用 ftp_rename 函数

    ftp_rename($conn_id, $old, $newfile);
    

    在此处查看详细信息:http://php.net/manual/en/function.ftp-rename.php

    【讨论】:

    • ftp_rename(): Sorry, but that file doesn't exist 然而echo file_exists($old); 返回 1
    • file_exists 将签入您的服务器。而ftp_rename 将检查 ftp 连接的服务器。
    猜你喜欢
    • 2015-08-16
    • 1970-01-01
    • 2021-10-13
    • 2021-11-04
    • 1970-01-01
    • 1970-01-01
    • 2012-12-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多