Web Analytics Made Easy -
StatCounter creating file and directory error - CodingForum

Announcement

Collapse
No announcement yet.

creating file and directory error

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • creating file and directory error

    PHP Code:
        mkdir($username);
        
    $create  =  fopen("/$username/$username.txt",  "w+");
        
    fputs($create,  "$username");
        
    fclose($create); 



    That code creates the directory because i can see it with my ftp client...but it doesnt put the file in the directory...i get this error:

    Warning: fopen(/yyy/yyy.txt): failed to open stream: No such file or directory in /var/www/html/forum/users/registerprocessor.php on line 31



    why is this? thanks.
    ~Designer's Toolz~

  • #2
    I put in the full path.. which is..



    mkdir($username);
    $create = fopen("http://64.141.105.108/forum/users/$username/$username.txt", "w+");
    fputs($create, "$username");
    fclose($create);



    and now i get this error:


    Warning: fopen(http://64.141.105.108/forum/users/ii/ii.txt): failed to open stream: HTTP wrapper does not support writeable connections. in /var/www/html/forum/users/registerprocessor.php on line 31



    whats that mean?
    ~Designer's Toolz~

    Comment


    • #3
      don't use a url for write operations use a relative path or file path

      eg fopen('http:// etc','w'); // << wont work
      fopen('/home/user/blah',''w'); // << will work
      as will
      fopen('blah','w'); // (would create the file 'blah' in the current working directory)

      PHP Code:
      <?php
      mkdir
      $username 0777 ) ;
      $fp =  fopen("$username/$username.txt",  "w+");
      fputs($fp,  "$username");
      fclose($fp);
      chmod$username 0775 ) ;
      ?>
      the chances are that the directory $username already exists and does not have the correct permissions set allow write operations.
      resistance is...

      MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

      Comment


      • #4
        the chances are that the directory $username already exists and does not have the correct permissions set allow write operations.


        No they dont exist....what the code is for is its making the directory $username and creating a file named $username.txt in that directory just created and it doesnt work. It just creates the directory but not the file...see first post for error.
        ~Designer's Toolz~

        Comment


        • #5
          the permissions for the directory created are:

          drwxr-xr-x
          ~Designer's Toolz~

          Comment


          • #6
            One thing I dont understand abuot the code....why did u change mode? Anyway, it works great. Can't think you enough..
            ~Designer's Toolz~

            Comment


            • #7
              Hi I chmod()'ded just to show that its generally a good idea as leaving a file or directory open at 0777 could allow other users on the server to `modify` those files.

              actually 0775 was a surreal example of what to chmod to but choose the mode that you feel is appropriate for the protection that your file requires.
              resistance is...

              MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

              Comment

              Working...
              X