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..
    ?>
Member Avatar for diafol

Perhaps file_put_contents() is easier?

chdir can place you into a specific directory though.

What about:

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

Thanks diafol works like a charm

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.