Welcome to Dream.In.Code
Become a PHP Expert!

Join 137,420 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,985 people online right now. Registration is fast and FREE... Join Now!




Text Files

 
Reply to this topicStart new topic

Text Files, Can't open text files from PHP script

deesdesk
7 Jan, 2008 - 04:41 AM
Post #1

New D.I.C Head
*

Joined: 6 Jan, 2008
Posts: 2

I have a php file that denies access to text files: "Warning: fopen(nursery.txt) [function.fopen]: failed to open stream: Permission denied in D:\web\Parishes\massachusetts\stgeorgelynn\stgeorgelynn\index_copy.php on line 251".

It works on my personal host/server but I get th above error message on the organization's host/server.

I am implementing a visitor counter that contains 5 files so I am only sending a snippet of the index file that contains the attempt to read and write a file's contents.
I the entire code is needed, let me know.

You will find the code snippet near the bottom of the page commented as:
///////////////DEBUG/TEST/////////////////

Thanx in advance for any suggestions/help/advice! blink.gif
.......................................................................................................................
CODE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="keywords" content="church, orthodox church, Greek Orthodox Church, St. George, St. George, St. George Lynn" />
<title>St. George Greek Orthodox Church | Main Page</title>
<meta http-equiv="refresh" content="3600">
<link rel="stylesheet" type="text/css" href="text_styles.css" />

</head>

<body bgcolor="#FFFFFF">

<!-- Header: Banner and St. George Icon -->
<table align="center" bgcolor="#FFFFFF" border="0" cellpadding="0" cellspacing="0" width="739" class="outerBorder">
    <tr>
        <td width="150" rowspan="3" valign="top" bgcolor="#990000"><a href="index.php"><img src="images/icon_stg.gif" alt="St. George Icon Image" border="1" width="150" height="264" /></a><br />
          <br /><span class="vertNav">Read about the life of our patron Saint:</span>
            <a href="life_stg.html" class="vertMenu"><strong>Saint George The Holy Great Martyr and Triumphant</strong></a>
            <hr />
            <div class="vertNav">Sunday Worship<br />
              <span class="style5">Orthos 9am</span><br />
              <span class="style5">Divine Liturgy 10am</span></div>
            <br />
      <img src="images/seal_100yrs.gif" alt="100 Years Seal Image" border="1" width="150" height="131" /></td>
        <td width="589" height="146" valign="top" bgcolor="#990000"><img src="images/header_shadow.gif" alt="St. George Greek Orthodox Church of Lynn Banner/Header" border="1" width="589" height="146" /></td>
    </tr>
    <tr>
        <td valign="top" bgcolor="#FFFFFF">
    
        <!-- End header -->    
    
            <!-- Begin date row then content area -->
    
                        <!-- Begin DATE display -->
            <table width="589" border="0" cellpadding="8" cellspacing="0">
                <tr>
                    <td align="center" valign="top" class="date">                        
                        <?php
                            // Get weekday number
                            $weekday = date("w");
                            // Get Full month, 2-digit day and year
                            $today = date("F j, Y");
                            // Get text representation of weekday name
                            $day = date("l");
                            // Display day of week
                            print($day.', ');
                            // Display date
                            print($today);
                        ?>                    
                  </td>
              </tr>
            </table>
            <!-- End date display -->    
            
            <!-- Begin main content area (1 table and 2 columns): below the menu and to the right of the icon and sidebar -->    
            <table width="589" border="0" align="right" cellpadding="10" cellspacing="0" class="tableBorder">
                <tr>
                    <td width="265" valign="top">
        
                        <!-- Begin content in Column 1, Table 1 -->
                        <table border="1" align="center" cellpadding="10" cellspacing="0" bordercolor="#990000" width="254">
                            <tr>
                                <td bgcolor="#990000" class="tableBorder" valign="top" ><h1>Welcome to our Parish</h1></td>
                            </tr>
                            <tr>
                                <td class="bodytext"><strong><em>Priest's Message</em></strong> <br />

                                It gives me great pleasure to welcome you to the St. George Web site and to introduce you to the
                                    many ministries offered at our Church. Our goal is to assist you in your spiritual growth and development.  Read more...</td>
                            </tr>
                        </table>
                        <br />
                        
                        <br />
                        <table border="0" align="center" bordercolor="#990000" class="smTableBorder" cellpadding="7" cellspacing="0" width="254">
              <tr>
                <th colspan="4" bgcolor="#990000" valign="top"><h1>News and Events</h1></th>
              </tr>
              <tr>
                <td align="center" width="20%"><img src="images/xmas_stocking.gif" alt="xmas stocking image" border="0" width="40" height="62" align="left" /></td>
                                <td align="center" class="pgLinks" width="60%"><a href="news_events.php" class="style1">Christmas Message<br />
                              and More </a></td>
                                <td width="20%"><img src="images/xmas_tree.gif" alt="xmas tree image" width="50" height="55" align="right" /></td>
                            </tr></span>
                        </table>
                            
                    </td>
                    <!-- End Column 1, Table 3 -->
                    
                    <!-- Begin Column 2 -->
                    <td width="284" valign="top">
                        
                        <!-- Begin ICON and GOSPEL/EPISTLE -->
                        <table align="center" border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td class="epiLinks" valign="top"><img src="images/icon_epiphany.gif" alt="Epiphany Icon" align="left" width="130" height="185" hspace="7" /><br />
                                <h2>Epistle Reading<br />
                                    <?php
                                        include("epistle_links.php");
                                        $getepiLinks = ($epiLinks[$epiLinksTimer]);
                                        //include $getLinks;    
                                        echo $getepiLinks;
                                    ?>
                                </h2>
                                <h2>Gospel Reading<br />
                                    <?php
                                        include("gospel_links.php");
                                        $getGospLinks = ($gospLinks[$gospLinksTimer]);
                                        //include $getGospLinks;    
                                        echo $getGospLinks;
                                    ?>
                                </h2>
                                </td>
                            </tr>
                        </table>
                        <!-- End GOSPEL & EPISTLE links -->
                        
                        <!-- Begin SAINTS and FEASTS  -->
                        <table align="center" border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td align="center" valign="top"><h2>Saints and Feasts<br />
                                    <?php
                                        include("saints_feasts_list.php");
                                        $getSaints = ($saints[$saintsTimer]);
                                        //include $getSaints;    
                                        echo $getSaints;
                                    ?>
                                    </h2>
                                </td>
                            </tr>
                        </table>
                        <!-- End SAINTS and FEASTS -->        
                        
                        
                        <br />
                        <!-- End ORTHODOX LINKS -->
                       <!-- Begin ORTHODOX MKTPLCE -->
                      <table align="center" width="240" border="0" cellspacing="0" cellpadding="7">
              <tr>
                <td align="center" valign="bottom"><a class="pgLinks" href="http://www.orthodoxmarketplace.com"></a>
                                    <a href="http://www.orthodoxmarketplace.com/"><img src="images/ortho_mktplce.gif" alt="Orthodox Marketplace Image" width="240" height="129" border="0" /></a><a class="pgLinks" href="http://www.orthodoxmarketplace.com"><br />
                                www.orthodoxmarketplace.com</a></td>
              </tr>
                            <tr>
                                <td>
                                <table>
                                        <tr>
                                            <td>
                                                <?php
                                                
                                                ///////////DEBUG/TEST//////////////
                                                $fp = fopen("nursery.txt", "w") or die("Can't open");
                                                fputs($fp, "Mary had a little lamb");
                                                fputs($fp, "the doctor was surprised");
                                                fclose($fp);
                                                print "code: $fp";
        
                                                //    include('counter/counter.php');
                                                //    include('counter/show_counter.php');
                                                ?>
                                            </td>
                                        </tr>
                                    </table>
                    </td>
                              </tr>
                            
                        </table>
            </table>
        </td>
    </tr>
</table>
</body>
</html>


[mod edit] In the future, please use the code tags.
User is offlineProfile CardPM
+Quote Post

pe_mitev
RE: Text Files
7 Jan, 2008 - 06:10 AM
Post #2

D.I.C Head
Group Icon

Joined: 28 Dec, 2007
Posts: 71


Dream Kudos: 50
My Contributions
I do not have much time to read all the topic but why don't you use chmod() to set rights for the current script? If it still does not work, change the rights of the script to 777, for example, via FTP.

This post has been edited by pe_mitev: 7 Jan, 2008 - 06:20 AM
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Text Files
7 Jan, 2008 - 06:13 AM
Post #3

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,550



Thanked: 67 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
I don't think you can chmod on a windows system.

1.) Are you sure that the file exists? Maybe you should test for it's existence before trying to open it.

2.) Try opening it with r instead of w. See if you can at least open it & read from it, then try to write to it.
User is offlineProfile CardPM
+Quote Post

deesdesk
RE: Text Files
7 Jan, 2008 - 08:31 AM
Post #4

New D.I.C Head
*

Joined: 6 Jan, 2008
Posts: 2

QUOTE(no2pencil @ 7 Jan, 2008 - 07:13 AM) *

I don't think you can chmod on a windows system.

1.) Are you sure that the file exists? Maybe you should test for it's existence before trying to open it.

2.) Try opening it with r instead of w. See if you can at least open it & read from it, then try to write to it.




The file exists and I can open and read from it on one host/server but not on the other server I am using.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/5/08 04:25AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month