File Creator Error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
azylka
Forum Commoner
Posts: 40
Joined: Sat Dec 06, 2008 9:11 pm

File Creator Error

Post by azylka »

I got an error saying that permission to open and write to a file on line 9 is denied. Line 9 is as follows:

Code: Select all

 $out = fopen($page, "w");
[edit]I fixed the error. There shouldn't have been a semi-colon at the end. But now I have a new error on line 10. Anyone have ideas?[/edit]

I know that the error in line 9 and the error in line 10 are related because they're in the same statement. What am I doing wrong?

user_reg.php:

Code: Select all

<?php
  $name = $_GET["name"];
  $user = $_GET["user"];
  $email = $_GET["email"];
  $pass = $_GET["pass"];
  $pgname = strtolower($user);
  $page = $pgname.".php";
print("<meta http-equiv=\"refresh\" content=\"5;url=$page\" />");
  $handle = fopen("$page", "w")
  if (!$handle) {
    die("Could not create file. Try your upload again.");
  }  
fwrite($out,"
 
<title>delilac | my account</title>
<div id=\"page\">
    <div id=\"content\">
        <div class=\"post\">
            <h1 class=\"title\">my account</h1>
            <div class=\"entry\">
                <p>
                Name: $name
                <br>
                Username: $user
                <br>
                Email Address: $email
                <br>
                Password: $pass
                <br>
                <br>
                -Having problems? Want to change a password? Click <a href=\"support.php?user=$user\">here</a> to contact support. 
                NOTE: When contacting support to change your personal details, you will receive an email asking to confirm this. If you get the email by accident, reply saying that you do not wish to change any details.
                </p>
            </div>
            <div class=\"meta\">
            </div>
        </div>
        <div class=\"post\">
            <h2 class=\"title\">post a link</h2>
            
            <div class=\"entry\">
                <p><form method=\"GET\" action=\"user_post.php\">
<input type=\"hidden\" name=\"user\" value=\"$user\">
Site Name: <br><input name=\"name\" value=\"ex. Google\">
<br>
Site Description: <br><textarea name=\"title\" rows=\"10\" cols=\"30\">A descripton of your site here. Remember: the longer, the better!</textarea>
<br>
Link to Site: <br><input name=\"url\" value=\"http://www.\">
<br>
<input type=\"submit\" value=\"Submit Site\">
</form></p>
                <ul>
                    
                </ul>
            </div>
            <div class=\"meta\">
            </div>
        </div>
    </div>
    <!-- end #content -->
    <div id=\"sidebar\">
        <div id=\"sidebar-bgtop\"></div>
        <div id=\"sidebar-content\">
            <ul>
                
                <li>
                    <h2>Login</h2>
                    <ul>
                                        You are logged in.
                                            <br>
                                          - <a href=\"index.php?log_out\"><u>Logout</u></a>
 
                    </ul>
                </li>
                <li>
                    <h2>Top 5 Links - Coming Soon!</h2>
                    <ul>
                        <li><a href=\"\"></a></li>
                        <li><a href=\"\"></a></li>
                        <li><a href=\"\"></a></li>
                        <li><a href=\"\"></a></li>
                        <li><a href=\"\"></a></li>
                        
                    </ul>
                </li>
            </ul>
        </div>
        <div id=\"sidebar-bgbtm\"></div>
    </div>
    <!-- end #sidebar -->
</div>
<!-- end #page -->
<div id=\"footer\">
    <p></p>
</div>
<!-- end #footer -->
</body>
</html>
 
");
  fclose($out);
?>
</div>
divito
Forum Commoner
Posts: 89
Joined: Sun Feb 22, 2009 7:29 am

Re: File Creator Error

Post by divito »

Your second code snippet fills a value into $handle, yet you call $out to write and close, outside of a missing semi-colon on line 9.
azylka
Forum Commoner
Posts: 40
Joined: Sat Dec 06, 2008 9:11 pm

Re: File Creator Error

Post by azylka »

Ok. I fixed that and now the code says:
Warning: fopen(.php) [function.fopen]: failed to open stream: Permission denied in /home/a4842522/public_html/user_reg.php on line 9

Here's the new code:

Code: Select all

<?php
  $name = $_GET["name"];
  $user = $_GET["user"];
  $email = $_GET["email"];
  $pass = $_GET["pass"];
  $pgname = strtolower($user);
  $page = $pgname.".php";
print("<meta http-equiv=\"refresh\" content=\"5;url=$page\" />");
  $handle = fopen("$page", "w");
  if (!$handle){
    die("Error");
}  
fwrite($handle,"
 
<title>delilac | my account</title>
<div id=\"page\">
    <div id=\"content\">
        <div class=\"post\">
            <h1 class=\"title\">my account</h1>
            <div class=\"entry\">
                <p>
                Name: $name
                <br>
                Username: $user
                <br>
                Email Address: $email
                <br>
                Password: $pass
                <br>
                <br>
                -Having problems? Want to change a password? Click <a href=\"support.php?user=$user\">here</a> to contact support. 
                NOTE: When contacting support to change your personal details, you will receive an email asking to confirm this. If you get the email by accident, reply saying that you do not wish to change any details.
                </p>
            </div>
            <div class=\"meta\">
            </div>
        </div>
        <div class=\"post\">
            <h2 class=\"title\">post a link</h2>
            
            <div class=\"entry\">
                <p><form method=\"GET\" action=\"user_post.php\">
<input type=\"hidden\" name=\"user\" value=\"$user\">
Site Name: <br><input name=\"name\" value=\"ex. Google\">
<br>
Site Description: <br><textarea name=\"title\" rows=\"10\" cols=\"30\">A descripton of your site here. Remember: the longer, the better!</textarea>
<br>
Link to Site: <br><input name=\"url\" value=\"http://www.\">
<br>
<input type=\"submit\" value=\"Submit Site\">
</form></p>
                <ul>
                    
                </ul>
            </div>
            <div class=\"meta\">
            </div>
        </div>
    </div>
    <!-- end #content -->
    <div id=\"sidebar\">
        <div id=\"sidebar-bgtop\"></div>
        <div id=\"sidebar-content\">
            <ul>
                
                <li>
                    <h2>Login</h2>
                    <ul>
                                        You are logged in.
                                            <br>
                                          - <a href=\"index.php?log_out\"><u>Logout</u></a>
 
                    </ul>
                </li>
                <li>
                    <h2>Top 5 Links - Coming Soon!</h2>
                    <ul>
                        <li><a href=\"\"></a></li>
                        <li><a href=\"\"></a></li>
                        <li><a href=\"\"></a></li>
                        <li><a href=\"\"></a></li>
                        <li><a href=\"\"></a></li>
                        
                    </ul>
                </li>
            </ul>
        </div>
        <div id=\"sidebar-bgbtm\"></div>
    </div>
    <!-- end #sidebar -->
</div>
<!-- end #page -->
<div id=\"footer\">
    <p></p>
</div>
<!-- end #footer -->
</body>
</html>
 
");
  fclose($handle);
?>
</div>
Thanks,
Alex
divito
Forum Commoner
Posts: 89
Joined: Sun Feb 22, 2009 7:29 am

Re: File Creator Error

Post by divito »

Now you need to check whether you have the permissions assigned to that file and the folder it is in for writing.
azylka
Forum Commoner
Posts: 40
Joined: Sat Dec 06, 2008 9:11 pm

Re: File Creator Error

Post by azylka »

Thanks. I thought I had already changed the permissions on the folder user_reg.php was in. Guess not.

Thanks,
Alex
Post Reply