PHP在服务器上创建文本文件

问题描述:

在我的php应用程序中,我想以文本格式创建错误日志,因此尝试在本地计算机上正常运行

In my php application i want to create a error log in a text format so tried like this its working fine in my local machine

if(!$mail->Send())
{
 echo "Message could not be sent. <p>";
 echo "Mailer Error: " . $mail->ErrorInfo;
 $stringData = "Error Info: ".$mail->ErrorInfo."\t\t";
 $stringData .= "Email to reciepient \t Regnumber: ".$RegNo." \t  Apllicant Name: ".$ApplicantName." Failed --- end ----";


 $fp = fopen($_SERVER['DOCUMENT_ROOT']."/lib/email_errorlog.txt","wb");
 fwrite($fp,$stringData);
 fclose($fp);

 exit;
  }

我已经在> PHP创建和将txt文件保存到根目录,但对我不起作用.问题是,没有错误显示,但未创建文本文件.需要在服务器上设置任何权限吗?

i have already seen discussion in PHP Create and Save a txt file to root directory but its not working for me. The problem is, there is no error is showing but text file is not creating. Need to set any permission on the server?

您必须确保:

  • 文件夹/lib在文档根目录中
  • webserver process有权写入该文件夹.
  • the folder /lib exists in the document root
  • the webserver process has permission to write to that folder.

如果使用您的 ftp帐户创建文件夹,则网络服务器进程将具有 no 访问权限.您可以将权限设置为777,但是每个人都可以访问.最好将权限设置为770,并使文件夹组成为Web服务器组ID.

If you create the folder with your ftp account, the webserver process will have no access. You can set permissions to 777, but then everyone has access. Best would be to set permission to 770 and make the group of the folder the webserver group id.