【问题标题】:Referencing file from realpath PHP从 realpath PHP 中引用文件
【发布时间】:2023-04-10 02:22:01
【问题描述】:

我在这里有一个处理 FTP 内容的类:

/var/www/html/crm/rhinos/classes/ftp.php

这个类包含在一个在这里生成电子表格的脚本中:

/var/www/html/crm/send_cust_lock.php

生成的电子表格位于此处:

/var/www/html/crm/tmp/cust_lock_1430424215.xlsx

我的类包含以下方法:

public function put($filepath){
    $fp = fopen($filepath, 'r');
    $z = ftp_fput($this->connection, $filepath, $fp, FTP_BINARY);
    fclose($fp);
    return $z;
}

从我的send_cust_lock.php 脚本中,当我调用$ftp->put($fn);$fn 是电子表格的上述文件路径)时,我收到以下错误:

Warning: ftp_fput(): Can't open that file: No such file or directory in /var/www/html/crm/rhinos/classes/ftp.php on line 62

fopen() 不会抛出错误,那为什么ftp_put() 会抛出一个错误呢?

我尝试使用所选答案here 中的函数将路径转换为相对路径,但没有成功。如何将文件路径转换为 ​​ftp_put() 可以识别的内容?

【问题讨论】:

  • 您是否尝试通过 FTP 访问已运行的脚本/文件所在的服务器?
  • @JonathanKuhn,不,我正在尝试通过互联网将它从我的开发机器发送到远程服务器。
  • 好的,下一个问题,你的代码是ftp_fput(),但你的描述中提到了ftp_put()。你在哪方面需要帮助? Realpath() 将完全解析的绝对路径(作为字符串)返回到文件,如果找不到文件,则返回 false。只要这不是错误的,您应该可以将它与ftp_put 一起使用。
  • @JonathanKuhn,我非常确定问题出在文件路径上,我没有费心重新阅读手册。结果我什至不需要放置它的文件路径。问题已正确回答,感谢您的帮助!

标签: php ftp relative-path filepath realpath


【解决方案1】:

manual 表示值是:

ftp_fput ( resource $ftp_stream , string $remote_file , resource $handle , int $mode [, int $startpos = 0 ] )

而你正在通过:

$z = ftp_fput($this->connection, $filepath, $fp, FTP_BINARY);

您的$fp 是本地文件的句柄,但为什么要传递与$remote_file 相同的路径?它不会在远程 FTP 上找到它,因为您传递了本地文件名。

【讨论】:

    猜你喜欢
    • 2023-01-04
    • 1970-01-01
    • 2011-05-02
    • 1970-01-01
    • 2015-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-20
    相关资源
    最近更新 更多