Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: writting files

  1. #1
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default writting files

    I don't have any code for this just a question. Can php write to an html file thats on a server. Right now i'm writing to a txt file then having the other html page open the text file and echo the contents. Also is there a way to create a text file with php. I've seen the 'x+' and the 'w+' on the fopen and everything i've seen says attempts to write to the file I don't get why it says attempt why not just do it and if it can't why not say it just writes to it and not mention creating the file.

    Thanks for ideas or comments.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    I don't exactly get what you want. Do you want to have a php file write to another php or html file. Do you wanna know what the x+, w+, a+, blahs and blahs do? Do you want to know how to make a file? Do you want to know why it attempts instead of just doing? Here:

    Writing to another php file, or a html file, is simple. You do the same thing you do when writing to a txt file. Although to get it to go where you want it in the html file is a bit more difficult.

    All of the operators do different things. I would explain what they do. But I don't know by heart, I just peak at a cheat-sheet every single time I code something that is in need of that kinda code. So here are some help pages:
    http://www.w3schools.com/PHP/php_file.asp
    http://www.tizag.com/phpT/fileopen.php

    It attempts instead of directly doing it for a few reasons. 1) It needs to see if its possible, for example it needs to see if this is on its domain, or someone elses. If its on someone elses, then it will return an error. 2) It needs to check the file permissions, for the folder, its own file, and the file its getting info from. For example I think that the file needs to be set to 777 CHMOD. But I don't know. 3) It needs to see if it gets the correct data.
    If it doesn't, then it will return an error.

    I hope this post helps you,
    Nile
    Jeremy | jfein.net

  3. #3
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    I get these messages:
    Code:
    Warning: fopen(video22.html): failed to open stream: Permission denied in /hsphere/local/home/crazychr/bluewalrus.net/testing.php on line 44
    
    Warning: fwrite(): supplied argument is not a valid stream resource in /hsphere/local/home/crazychr/bluewalrus.net/testing.php on line 45
    
    Warning: fclose(): supplied argument is not a valid stream resource in /hsphere/local/home/crazychr/bluewalrus.net/testing.php on line 46
    When I put this code in:
    Code:
    $File = "video22.html";
    $Handle = fopen($File, 'x+');
    fwrite($Handle, $pfile);
    fclose($Handle);
    also I've tried it as a txt file and a html. It doesn't make a difference, the directories set as 777, the file is not but can't be because it's suppose to be being created. This is on my own domain.

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Show me line 44, 445, 46 I suppose there is one because it gives an error about line 44, 45, 46 above where you posted, and here:
    http://bluewalrus.net/testing.php
    Jeremy | jfein.net

  5. #5
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    PHP Code:
    $Handle fopen($File'x+');
    fwrite($Handle$pfile);
    fclose($Handle);
        
    ?> 

    Thanks

  6. #6
    Join Date
    Apr 2006
    Posts
    190
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default

    Is the file chmod writeable 777
    Ryan
    Sevierville, TN

  7. #7
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    its suppose to be creating the file there is no file yet. the directory is 777

  8. #8
    Join Date
    Apr 2006
    Posts
    190
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default

    i had a sim problem and this worked for me:

    PHP Code:
    fopen($myFile'a+r+w+x+'
    Ryan
    Sevierville, TN

  9. #9
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    brings up the same errors

  10. #10
    Join Date
    Apr 2006
    Posts
    190
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default

    what is
    PHP Code:
    $pfile 
    mapping too??
    Ryan
    Sevierville, TN

Bookmarks

Posting Permissions

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