ftp_delete - 文件存在但未找到

时间:2016-03-29 09:05:44

标签: php ftp

我有奇怪的问题......你可以看到.. o.O

$connection = ftp_connect(FTP_SERVER);
$login = ftp_login($connection, FTP_USERNAME, FTP_PASSWORD);
if ($login) {
    $file = "" . DOCUMENT_ROOT . "/uploaded_files/" . Session::GetSession('username') . "/" . $result['ftp_file_name'] . "";
    if (file_exists($file)) {
        echo "file_exists";
        if (ftp_delete($connection, $file)) {
            echo "deleted";
        } else {
            echo "file_not_found";
        }
    } else {
        echo "does_not_exists";
    }
} else {
    echo "not_logged_in";
}

结果如下:

  

file_exists
警告:ftp_delete():找不到文件    C:\ programy \ xampp \ htdocs \ ajax-handler.php 235 file_not_found

谁能告诉我为什么会这样?它没有任何意义..

2 个答案:

答案 0 :(得分:0)

删除DOCUMENT_ROOT并在ftp_delete之前添加'(#)符号 尝试如下

 $fileTmp =  "/uploaded_files/" . Session::GetSession('username') . "/" .                $result['ftp_file_name'] .$get_file "";

    if (@ftp_delete($connection, $fileTmp)){

答案 1 :(得分:-1)

$connection = ftp_connect(FTP_SERVER);
            $login = ftp_login($connection, FTP_USERNAME, FTP_PASSWORD);
            if ($login) {
                $get_file=$_GET['uploaded_files'];
                $file = "" . DOCUMENT_ROOT . "/uploaded_files/" . Session::GetSession('username') . "/" . $result['ftp_file_name'] .$get_file "";
                if (file_exists($file)) {
                    echo "file_exists";
                    if (ftp_delete($connection, $file)) {
        echo "deleted";
                    } else {
                        echo "file_not_found";
                    }
                } else {
                    echo "does_not_exists";
                }
            }
        } else {
            echo "not_logged_in";
        }
ftp_close($connection);