File not found in directory
Results 1 to 3 of 3

Thread: File not found in directory

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    6

    File not found in directory

    This is supposed to be a song Organizer script that stores songs in a text file. It allows users to view the song list and prevents the same song name from being entered twice. Also, it sorts the songs by name, deletes duplicate entries, and randomizes the song list. The problem I having is whenever I click "Add song to list" the script does not create a new file and I receive an error saying "Warning: fopen(SongOrganizer/songs.txt) [function.fopen]: failed to open stream: No such file or directory on line 69". I indicated line 69 with comments. Can someone please help me?

    HTML Code:
    <html>
    <h1>Song Organizer</h1>
    PHP Code:
    <?php
    if (isset($_GET['action']))
    {
        if ((
    file_exists("SongOrganizer/songs.txt")) && (filesize("SongOrganizer/songs.txt") != 0)) 
        { 
            
    $SongArray file"SongOrganizer/songs.txt"); 
            switch (
    $_GET['action']) 
            { 
                case 
    'Remove Duplicates'
                
    $SongArray array_unique$SongArray); 
                
    $SongArray array_values$SongArray); 
                break; 
                case 
    'Sort Ascending'
                
    sort($SongArray); 
                break; 
                case 
    'Shuffle'
                
    shuffle($SongArray);
                break;
            } 
    // End of the switch statement 
            
    if (count($SongArray)>0
            { 
                
    $NewSongs implode($SongArray); 
                
    $SongStore fopen"SongOrganizer/songs.txt""wb"); 
                    if (
    $SongStore === false
                    echo 
    "There was an error updating the song file\n";
                    else 
                    { 
                        
    fwrite($SongStore$NewSongs); fclose($SongStore); 
                    } 
            } 
            else 
                
    unlink("SongOrganizer/songs.txt"); 
        } 
    }

    if (isset(
    $_POST['submit']))
    {
        
    $SongToAdd stripslashes$_POST['SongName']). "\n"
        
    $ExistingSongs = array(); 
        if (
    file_exists("SongOrganizer/songs.txt") && filesize("SongOrganizer/songs.txt") > 0)
        { 
            
    $ExistingSongs file"SongOrganizer/songs.txt"); 
        }
        if (
    in_array($SongToAdd$ExistingSongs)) 
        { 
            echo 
    "<p>The song you entered already exists!<br />\n"
            echo 
    "Your song was not added to the list.</p>"
        }
        else 
        { 
            
    $SongFile fopen"SongOrganizer/songs.txt""ab"); 
            if (
    $SongFile === false
                echo 
    "There was an error saving your message!\n"
            else 
            { 
                
    fwrite($SongFile$SongToAdd); 
                
    fclose($SongFile); 
                echo 
    "Your song has been added to the list.\n"
            } 
        }
    }

    if ((!
    file_exists("SongOrganizer/songs.txt")) || (filesize("SongOrganizer/songs.txt") == 0)) 
        echo 
    "<p>There are no songs in the list.</p>\n"
    else
    {
            
    //THIS IS LINE 69
        
    $SongArray file"SongOrganizer/songs.txt"); 
        echo 
    "<table border=\"1\" width=\"100%\" style=\"background-color:lightgray\">\n"
        foreach (
    $SongArray as $Song)
        {
            echo 
    "<tr>\n"; echo "<td>"htmlentities($Song). "</td>"
            echo 
    "</tr>\n"
        } 
        echo 
    "</table>\n";
    }
    ?>
    HTML Code:
    <p> <a href="SongOrganizer.php?action=Sort%20Ascending"> Sort Song List</a><br />
     <a href="SongOrganizer.php?action=Remove%20Duplicates"> Remove Duplicate Songs</a><br /> 
     <a href="SongOrganizer.php?action=Shuffle"> Randomize Song list</a><br /> </p>
    <form action="SongOrganizer.php" method="post"> 
    <p>Add a New Song</p> 
    <p>Song Name: <input type="text" name="SongName" /></p>
    <p><input type="submit" name="submit" value="Add Song to List" /> 
    <input type="reset" name="reset" value="Reset Song Name" /></p> </form>
    </html>

  2. #2
    Syntax Error
    Join Date
    Feb 2003
    Location
    San Diego, CA
    Posts
    443
    Does the 'SongOrganizer' folder have write permissions?

    Does it work if you specify the entire path rather than relative?

  3. #3
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,428
    Quote Originally Posted by Phpscrub View Post
    This is supposed to be a song Organizer script that stores songs in a text file.
    Why? Why not use something better suited for the job, such as a DBMS like MySQL (or even SQLite)?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •