PHP“无法访问文件:”

时间:2013-12-26 08:31:18

标签: php

我在career.php页面中使用此代码。

Warning: file_get_contents(/home/eigeny6s/public_html/text.txt) [function.file-get-contents]: failed to open stream: No such file or directory in /home/eigeny6s/public_html/career.php

此外,我已在ftp中设置了public.html的0777。

我的代码是:

function mail_attachment($filename, $path, $mailto, $from_mail,
                         $from_name, $replyto, $subject, $message)
{


    $file = $path.$filename;
    print_r($file);
    $file_size = filesize($file);
    $handle = fopen($file, "r");
    $content = fread($handle, $file_size);
    fclose($handle);
    $content = file_get_contents($strFilesName);
    $content = chunk_split(base64_encode($content));
    $header .= "--".$uid ."\n";  
    $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\n\n";  
    $header .= "Content-Type: application/octet-stream; name=\"".$filename ."\"\n";  
    $header .= "Content-Transfer-Encoding: base64\n";  
    $header .= "Content-Disposition: attachment; filename=\"".$filename ."\"\n\n";  
    $header .= $content."\n\n";  
    $name = basename($file);
    $header = "From: ".$from_name." <".$from_mail.">\r\n";
    $header .= "Reply-To: ".$replyto."\r\n";
    $header .= "MIME-Version: 1.0\r\n";
    $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
    $header .= "This is a multi-part message in MIME format.\r\n";
    $header .= "--".$uid."\r\n";
    $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
    $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
    $header .= $message."\r\n\r\n";
    $header .= "Name: ".$_POST["name"]."\n\n";  
    $header .= "E-mail: ".$_POST["email"]."\n\n";
    $header .= "Position: ".$_POST["position"]."\n\n";
    $header .= "Phone: ".$_POST["phone"]."\n\n";
    $header .= "--".$uid."\r\n";
    $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here
    $header .= "Content-Transfer-Encoding: base64\r\n";
    $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
    $header .= $content."\r\n\r\n";
    $header .= "--".$uid."--";

        if (mail($mailto, $subject, "", $header)) {
        echo "mail send ... OK"; // or use booleans here
        } else {
        echo "mail send ... ERROR!";
        }

}

1 个答案:

答案 0 :(得分:0)

根据您所描述的内容,文件/home/eigeny6s/public_html/text.txt可能不存在。

您的代码正在尝试阅读此文件,可能是因为这是$strFilesName

要修复它,你可以:

  • 确保此text.txt文件存在
  • 或更改$strFilesName
  • 的值

或者,如果您不能保证此文件存在,您可以先检查它:

$content = "default text used if I don't have my file";
if ( file_exists($strFilesName) ){
  $content = file_get_contents($strFilesName);
}