PHP在服务器上创建文本文件 [英] PHP create text file on server

查看:155
本文介绍了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.

这篇关于PHP在服务器上创建文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆