+ Reply to Thread
Page 2 of 2
FirstFirst 1 2
Results 11 to 14 of 14

Thread: Create files with php

  1. #11
    Newbie Hrimthurs is an unknown quantity at this point
    Join Date
    Jan 2008
    Posts
    8

    Re: Create files with php

    I use this code, and find it works on my server at PHP Version 4.4.8

    Code:
    <?
    $url 
    $_REQUEST['url'];

    if (
    $url != ''){
    $file = isset($_POST['file']) ? $_POST['file']:$url;
    $data $_REQUEST['data'];
    $newfile fopen($file"w+") or die ("could not create file.");
    fclose($newfile);
    $myfile = @fopen($file"w+") or die ("could not open file.");
    @
    fwrite($myfile$data) or die ("could not write to file");
    fclose($myfile);
    $msg "<p>File created: <a href='$file'>$file</a><br/>Content:<br>$data</p>";
    echo 
    $msg;}
    else {echo 
    '<form action="?create=go" method="post" name="new">
    File name.extention: 
    <input name="url" type="text" size="30" maxlength="60" /><br/>
    File data: 
    <textarea name="data" size="30" id="data" ></textarea><br/>
    <input name="" type="submit" value="CREATE FILE" /></form>'
    ;}
    ?>

  2. #12
    Newbie sarang is an unknown quantity at this point
    Join Date
    Nov 2008
    Posts
    2

    Re: Create files with php

    hi ...Its work ...but where it stores the created file!!!!!!!

  3. #13
    Newbie Hrimthurs is an unknown quantity at this point
    Join Date
    Jan 2008
    Posts
    8

    Re: Create files with php

    With my code you can put "{foldername}/$file" into the code so it will look something like so:
    Code:
    <?php
    $url = $_REQUEST['url'];
    
    if ($url != ''){
    $file = isset($_POST['file']) ? $_POST['file']:$url;
    $data = $_REQUEST['data'];
    $newfile = fopen("tmp/$file", "w+") or die ("could not create file.");
    fclose($newfile);
    $myfile = @fopen("tmp/$file", "w+") or die ("could not open file.");
    @fwrite($myfile, $data) or die ("could not write to file");
    fclose($myfile);
    $msg = "<p>File created: <a href='$file'>$file</a><br/>Content:<br>$data</p>";
    echo $msg;}
    else {echo '<form action="?create=go" method="post" name="new">
    File name.extention: 
    <input name="url" type="text" size="30" maxlength="60" /><br/>
    File data: 
    <textarea name="data" size="30" id="data" ></textarea><br/>
    <input name="" type="submit" value="CREATE FILE" /></form>';}
    ?>

  4. #14
    Newbie sarang is an unknown quantity at this point
    Join Date
    Nov 2008
    Posts
    2

    Re: Create files with php

    but it will not show the contents of the file....it only create a file at given path.

+ Reply to Thread
Page 2 of 2
FirstFirst 1 2

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