dtnmuyoiw680512744 2013-10-29 08:05
浏览 495

PHP fopen()函数无法打开并且权限被拒绝

Am using XAMP 1.7.3 on Macbook pro osx 10.9 Firefox browser

Well basically i am trying to write a code asking the user to enter some information and then store the information in a .txt file using the:

 $txtfile="registration.txt";
 $handle=fopen($txtfile,'a');

But I keep getting the this error message :

Warning: fopen(registration.txt) [function.fopen]: failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/UserInfoAhmed.php on line 30

Warning: fwrite() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/UserInfoAhmed.php on line 31

Warning: fwrite() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/UserInfoAhmed.php on line 32

Warning: fwrite() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/UserInfoAhmed.php on line 33

Warning: fwrite() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/UserInfoAhmed.php on line 34

Warning: fwrite() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/UserInfoAhmed.php on line 35

full code is :

<html>
<head>
    <title>User Informations</title>
</head>

<body>
<form method="post" action="">
    Name    : <input type="text" name="name"/> <br>
    Age     : <input type="text" name="age"/> <br>
    City    : <input type="text" name="city"/> <br>
    Password: <input type="password" name="pswrd1"/> <br>
    Password: <input type="password" name="pswrd2"/> <br>
    <input type="submit" name="submit" value"send"/>
    <form/>
    <?php

    if(isset($_POST['submit']))
    {

        $name=$_POST["name"];
        $age=$_POST["age"];
        $city=$_POST["city"];
        $pswrd1=$_POST["pswrd1"];
        $pswrd2=$_POST["pswrd2"];

        if($pswrd1 == $pswrd2){
            if($city==dubai){
                if($age>18){
                    $txtfile="registration.txt";
                    $handle=fopen($txtfile,'a');
                    fwrite($handle, $name);
                    fwrite($handle, $age);
                    fwrite($handle, $city);
                    fwrite($handle, $pswrd1);
                    fwrite($handle,$pswrd2);                    
                }
                else echo "age must be > 18";
            }
            else echo "city must be dubai";
        }
        else echo "password must identical";
        echo "<br>";



    }

    ?>
</body>

first i understood the first error message, failure to access / create the .txt file, and as i searched in this website, several ppl had the same problem, some the suggested a permission problem with the main file, and since every time i try to update the php file i get asked to enter my admin password, so i assumed the XAMP main file also protected

i changed the file option to read & write by all users, and all the folders within the main XAMP folder. but still i get asked for the password to save any changes in the php file am writing this code in, and thus i guess am still getting the same : fopen(registration.txt) [function.fopen]: failed to open stream: Permission denied in ...

so how could i fix this ? also am wondering if the rest of error messages related to the main problem ?

all in all, could someone tell me at least if there is a mistake in my code ?

  • 写回答

1条回答 默认 最新

  • douzi4766 2013-10-29 08:23
    关注

    First

    Try to set registration.txt permissions via console:

    sudo chmod 0777 /Applications/XAMPP/xamppfiles/htdocs/registration.txt
    

    Second

    If first didn't work then I think that you should change your htdocs folder location, because when it's in Applications folder it might not work properly because Applications folder might be somehow protected by system.

    Edit your XAMPP apache httpd.conf and set DocumentRoot to /users/USERNAME/Documents/htdocs

    Be sure to create htdocs folder under your Documents folder.

    Then in console change folder permissions:

    sudo chmod 0777 /users/USERNAME/Documents/htdocs
    

    Then try to put some random file in the folder and try to open it in browser

    http://localhost/randomfile.php
    

    It should work. If you are getting internal server error (500) then comment out following line in httpd.conf:

    LoadModule hfs_apple_module libexec/apache2/mod_hfs_apple.so
    
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向