我正在尝试使用CSV文件构建列表电子邮件,问题是我在simpel网站上使用CMS它的工作原理! 当我整合在我的cms中时,它停止工作并且说:
禁止访问!您无权访问所请求的对象。它受读保护或服务器无法读取。如果您认为这是服务器错误,请联系webmaster.Error 403127.0.0.1Apache / 2.4.7(Win32)PHP / 5.5.8
这是我在离线页面上的代码:
</div><div class="clear"></div>
<form name="form1" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" class="subscribe">
<input type="text" id="notify_by_mail" name="notify_by_mail" class="email"/>
<input type="submit" name="submit" value="GO" class="submit"/>
</form>
这是php文件代码:
<?php
if($_POST['formSubmit'] == "GO")
{
$varName = $_POST['notify_by_mail'];
$file = 'user_emails.csv'; /* The .csv file */
$fs = fopen($file,"a"); /* Opens up the csv file called user_emails.csv. */
fwrite($fs,$varName . ", \n"); /* And writes the submitted email to it */
fclose($fs);
chmod($file,0622); /* Permissions */
?>
<script type="text/javascript">
$(document).ready(function() {
/* When the user submits his e-mailaddress successfully, the next comment will show below the form. */
$("#notify_by_mail").after("<span class='error'>Your e-mailaddress has been submitted to us.</span>");
});
</script>
<?php
}
?>
我已添加到.htaccess文件中:
<FilesMatch "\.(csv)$|^$">
Order deny,allow
Allow from all
</FilesMatch>
禁止访问!您无权访问所请求的内容 宾语。它受读保护或服务器无法读取。如果 您认为这是服务器错误,请联系webmaster.Error 403127.0.0.1Apache / 2.4.7(Win32)PHP / 5.5.8
可以来自.htaccess吗?
答案 0 :(得分:0)
您正在使用十进制值,您应该使用十六进制。
chmod($file,0622);
相当于:chmod($file,0x026E);
更改:
chmod($file,0622);
要:
chmod($file,0x0622);
打开并写入文件后,不确定是否需要chmod:
$varName = $_POST['notify_by_mail'];
$file = 'user_emails.csv'; /* The .csv file */
$fs = fopen($file,"a"); /* Opens up the csv file called user_emails.csv. */
fwrite($fs,$varName . ", \n"); /* And writes the submitted email to it */
fclose($fs);
chmod($file,0622); /* Permissions */
您可能希望在打开和写入之前将chmod移动。
$varName = $_POST['notify_by_mail'];
chmod($file,0622); /* Permissions */
$file = 'user_emails.csv'; /* The .csv file */
$fs = fopen($file,"a"); /* Opens up the csv file called user_emails.csv. */
fwrite($fs,$varName . ", \n"); /* And writes the submitted email to it */
fclose($fs);
如果问题仍然存在,请查看权限和文件信息:
echo substr(sprintf('%o', fileperms($file)), -4);
var_dump(stat($file));
如果您对公共访问有疑虑,请将文件移至私人目录,例如:/home/user/etc