dqwmhrxt68679 2008-11-11 04:35
浏览 145
已采纳

使用PHP时如何获取FTP错误

I have a script which logs on to a remote server and tries to rename files, using PHP.

The code currently looks something like this example from the php.net website:

if (ftp_rename($conn_id, $old_file, $new_file)) {
 echo "successfully renamed $old_file to $new_file
";
} else {
 echo "There was a problem while renaming $old_file to $new_file
";
}

but ... what was the error? Permissions, no such directory, disk full?

How can I get PHP to return the FTP error? Something like this:

echo "There was a problem while renaming $old_file to $new_file: 
the server says $error_message
";
  • 写回答

4条回答 默认 最新

  • dtk31564 2008-11-11 04:39
    关注

    Looking at the FTP API here:

    http://us.php.net/manual/en/function.ftp-rename.php

    There doesn't seem to be any way to get anything but true or false.

    However, you could use ftp_raw to send a raw RENAME command, and then parse the returned message.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?