【问题标题】:Why can I not find the file if I give the relative path but I can find it with the direct path?如果我给出相对路径但我可以使用直接路径找到它,为什么我找不到该文件?
【发布时间】:2012-11-03 20:24:57
【问题描述】:

我正在尝试使用 mime->addAttachment() 将附件添加到我即将发送的电子邮件中

相对路径:../../clientdata/client1/attachments/file.txt

直接路径:/home/hosting/site.eu/html/ssl/clientdata/client1/attachments/file.txt

脚本位置:/home/hosting/site.eu/html/ssl/work/php_scripts/send_email.php

send_email.php 使用以下命令执行:

exec("php /home/hosting/site.eu/html/ssl/work/php_scripts/send_email.php");

这里有什么我遗漏的吗?

我用来添加附件的代码:

$f = 'ssl.site.eu/clientdata/client1/attachments/file1.txt';  
$arr_file = explode('/', $f, 2);
$file_path = '/home/hosting/site.eu/html/ssl/'.$arr_file[1]; //this works
// $file_path = '../../'.$arr_file[1]; // this doesn't work;
$mime->addAttachment($file_path,'application/octet-stream');

【问题讨论】:

  • 您需要向我们提供更多详细信息,说明您如何尝试使用 PHP“查找”文件。向我们展示您尝试“查找”文件的代码。

标签: php mime


【解决方案1】:

注意你的进程的工作目录。

下面的代码是否给出了正确的路径? echo getcwd().$relative_path;

PHP getcwd()

【讨论】:

  • hm,它给出了运行 exec() 的文件的路径。这就是问题所在。
【解决方案2】:

如果你包含一些相对于代码执行文件的PHP文件,你必须确保你包含这些文件相对于进程的当前目录,而不是文件包含当前正在执行的代码。

【讨论】:

    猜你喜欢
    • 2020-03-21
    • 1970-01-01
    • 2016-11-25
    • 1970-01-01
    • 2011-10-13
    • 1970-01-01
    • 2019-01-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多