0

Hello all its been a while, I have a question on the script below. Here is what I would like to do.
Take $file after fwrite has processed and add it to $dir.
The Script creates the Directory and the file. I just need it to add the File to the directory

    <?php

    $dir = 'myDir';
    $file = 'myFile.php';

    // check the directory to see if it already exists
    if( is_dir($dir) === false )
    {
        // if it doesn't make a new directory
        mkdir($dir);
    }

    // start a new stream


    $f = fopen($file, 'w'); // 'w' for write
    // write the php to the stream
    fwrite( $f, '<?php echo "Hello world! 123456"; ?>' );
    // close the stream
    fclose($f);

    // Now Take $file after fwrite has processed and add it to $dir.
    // The Script creates the folder and the file. I just need it to add this File to the folder now..
    ?>

Edited by wxflint

2
Contributors
2
Replies
14
Views
4 Years
Discussion Span
Last Post by wxflint
0

Perhaps file_put_contents() is easier?

chdir can place you into a specific directory though.

What about:

$file = $myDir . '/myFile.php';
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.