+ Reply to Thread
Page 1 of 2
1 2 LastLast
Results 1 to 10 of 14

Thread: Create files with php

  1. #1
    Moderator Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan's Avatar
    Join Date
    Dec 2006
    Location
    Estonia
    Age
    18
    Posts
    2,066
    Blog Entries
    9

    Create files with php

    Creating files with php is very simple. So.. let's start.

    Code:
    <?php

    // This function shows your form
    function form(){

    echo 
    "<form action='?act=create' method='post'>"
        
    ."Filename: <input type='text' name='filename' size='30'><br>"
        
    ."<textarea cols='50' rows='10' name='content'></textarea><br>"
        
    ."<input type='submit' value='Create'>"
        
    ."</form>";

    }

    // This function will create your file
    function create(){

    // Gather info into variables from our form
    $filename $_REQUEST['filename'];
    $content $_REQUEST['content'];

    // Now let's create our file
    $open fopen($filename"a"); // Now this file is ready for overwriting
    fwrite($open$content); // This will write your text what was in textarea into your file
    fclose($open); // Closes your file
    echo "File is created <a href='$filename'>Preview</a>";

    }

    switch(
    $act){

    default;
    form();
    break;

    case 
    "create";
    create();
    break;

    }

    ?>
    I hope it helped..

    Regards Jaan
    Last edited by Jaan; 03-02-2008 at 05:18 AM.
    Trill Hosting - Cheap SSL, Cheap Web Hosting, Register Cheap Domains, Cheap Blog Hosting
    www.trillhosting.com | support@trillhosting.com
    Hosting Plans | Write To Us | Support | Client Area | About Us

    CodeCall Blog | CodeCall Wiki

  2. #2
    Programming Professional Whitey has a spectacular aura about Whitey has a spectacular aura about Whitey has a spectacular aura about Whitey's Avatar
    Join Date
    Feb 2008
    Location
    Loveland, Colorado
    Posts
    244
    Doesn't work..

  3. #3
    Moderator Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan's Avatar
    Join Date
    Dec 2006
    Location
    Estonia
    Age
    18
    Posts
    2,066
    Blog Entries
    9
    yes it works
    i always check my tutorials before posting them here..
    Trill Hosting - Cheap SSL, Cheap Web Hosting, Register Cheap Domains, Cheap Blog Hosting
    www.trillhosting.com | support@trillhosting.com
    Hosting Plans | Write To Us | Support | Client Area | About Us

    CodeCall Blog | CodeCall Wiki

  4. #4
    Co-Administrator John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John's Avatar
    Join Date
    Jul 2006
    Age
    21
    Posts
    5,885
    Blog Entries
    25
    Quote Originally Posted by Whitey View Post
    Doesn't work..
    You're right, the code appends the file to a directory calls "files." If that folder doesn't exist, it wont work. If it does exist the file will be created, but the link won't work because it is isn't linked to the files directory.

  5. #5
    Moderator Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan's Avatar
    Join Date
    Dec 2006
    Location
    Estonia
    Age
    18
    Posts
    2,066
    Blog Entries
    9
    well.. this is VERY wierd.. because when I create my tutorials or just scritps then i always check do they work or not.. but i'll check it..and fix something
    Trill Hosting - Cheap SSL, Cheap Web Hosting, Register Cheap Domains, Cheap Blog Hosting
    www.trillhosting.com | support@trillhosting.com
    Hosting Plans | Write To Us | Support | Client Area | About Us

    CodeCall Blog | CodeCall Wiki

  6. #6
    Moderator Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan's Avatar
    Join Date
    Dec 2006
    Location
    Estonia
    Age
    18
    Posts
    2,066
    Blog Entries
    9
    Anyway.. now it works 100% and before it worked also..
    Trill Hosting - Cheap SSL, Cheap Web Hosting, Register Cheap Domains, Cheap Blog Hosting
    www.trillhosting.com | support@trillhosting.com
    Hosting Plans | Write To Us | Support | Client Area | About Us

    CodeCall Blog | CodeCall Wiki

  7. #7
    Newbie lucky-girl is an unknown quantity at this point lucky-girl's Avatar
    Join Date
    Dec 2007
    Age
    25
    Posts
    27
    nice and easy
    question
    action='?act=create'
    what is (?act) means?
    sorry, i know its stupid question
    thanks (flower)
    begginer programmer needs the help

  8. #8
    Moderator Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan's Avatar
    Join Date
    Dec 2006
    Location
    Estonia
    Age
    18
    Posts
    2,066
    Blog Entries
    9
    hmm..
    it's like.. main command and and create is a subcommand..
    you can change this act to what ever your like..
    Trill Hosting - Cheap SSL, Cheap Web Hosting, Register Cheap Domains, Cheap Blog Hosting
    www.trillhosting.com | support@trillhosting.com
    Hosting Plans | Write To Us | Support | Client Area | About Us

    CodeCall Blog | CodeCall Wiki

  9. #9
    Newbie mittalmak is an unknown quantity at this point
    Join Date
    Aug 2007
    Posts
    11

    Re: Create files with php

    tha code dose not work's

  10. #10
    Moderator Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan's Avatar
    Join Date
    Dec 2006
    Location
    Estonia
    Age
    18
    Posts
    2,066
    Blog Entries
    9

    Re: Create files with php

    yes it works..
    well for me...
    Trill Hosting - Cheap SSL, Cheap Web Hosting, Register Cheap Domains, Cheap Blog Hosting
    www.trillhosting.com | support@trillhosting.com
    Hosting Plans | Write To Us | Support | Client Area | About Us

    CodeCall Blog | CodeCall Wiki

+ Reply to Thread
Page 1 of 2
1 2 LastLast

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. PHP 4 end of life announcement
    By Jordan in forum News
    Replies: 4
    Last Post: 08-30-2007, 09:55 AM
  2. Where to Put PHP Code
    By clookid in forum PHP Tutorials
    Replies: 1
    Last Post: 01-11-2007, 08:44 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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