Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jul 2007
    Location
    Oskaloosa IA
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    writing file problem

    ok im new to php and when i say that im new i mean ive only been messin with it for a few days... so now heres my problem ive been folowing along wih a tutorial and ive got to the point that im using php to write files.. my problem is tht no matter what i do i can not get this thing to write a file.. can someone please look over the code that im using and/or give me some insigt on why i cant get this to work?


    Code:
    <?php 
    
    // set file to write
    $file = '/php/new.txt'; 
    // open file 
    $fh = fopen($file, 'w') or die('Could not open file!'); 
    // write to file 
    fwrite($fh, "Look, Ma, I wrote a file! ") or die('Could not write to file'); 
    // close file 
    fclose($fh); 
    
    ?>
    and yes i have the directory created on my server i also tried this code with no success

    Code:
    <?php 
    
    // set file to write
    $filename = '/php/new.txt'; 
    // write to file 
    file_put_contents($filename, "Look, Ma, I wrote a file! ") or die('Could not write to file'); 
    
    ?>
    thanks,
    jake

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,511
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    The file called "new.txt" needs to have it's permissions set to 777

    When you created the file, it probably defaulted to 466, so your
    script won't write to it.

    Use your FTP program or online file manager (control panel) to set permissions.

  • #3
    New to the CF scene
    Join Date
    Jul 2007
    Location
    Oskaloosa IA
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok so i changed he permissions and all that and i still cant get this to work. i know this sounds excessive but could someone write me a start to finsih in depth guide to writing a file with php? if so it would be much apperciated!

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,511
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    I tried your script and it works just fine for me ...

    PHP Code:
    <?php 

    // set file to write
    $file '/php/new.txt'
    // open file 
    $fh fopen($file'w') or die('Could not open file!'); 
    // write to file 
    fwrite($fh"Look, Ma, I wrote a file! ") or die('Could not write to file'); 
    // close file 
    fclose($fh); 

    ?>
    I created a directory called "php" and set permission to 777
    I created "new.txt" set permission to 777

    and it works just fine.

    Try writing to the same directory as the script ...
    $file = 'new.txt';


    You must not have something configured right with your directories?

  • #5
    New to the CF scene
    Join Date
    Jul 2007
    Location
    Oskaloosa IA
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    im going to try a new ftp program im using ftp explorer right now and i dont like it at all...

  • #6
    New to the CF scene
    Join Date
    Jul 2007
    Location
    Oskaloosa IA
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok so i got it to work finally, but now i have a new question.. am i supposed to be able to see it in my ftp browser? cuz i can see it when i go to www.mysite.com/new.txt but i cant see it in the ftp window? any ideas on what this may be?

    and thanks alot mlseim for all your help it really is appreciated by the newbie

  • #7
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,511
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    It must be a setting in your FTP program.

    I still like the outdated old WSFTP-LE ...

    You can find the downloads on the web ... like here:

    http://d321.k12.id.us/Support/Docs/FTP_CLIENTS/WSFTPLE/

    http://www.google.com/search?hl=en&q...=Google+Search

    It asks whether you are a student/teacher or not.
    Answer yes to being a student or teacher.

    It's just the very basic FTP, easy and quick.
    Set a few options, like open files using Notepad (provide the path to it).

  • #8
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    be sure that you are in the proper folder with your FTP explorer. EG public_html...


  •  

    Posting Permissions

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