CHASE
CHASE

Reputation: 511

How would I make php folder and create a file into that folder previously created

So I am trying to write a php script that creates a folder with files in it. But the problem is that the folder is being created but the file is not going into the correct destination. Here is the php I have atm:

<?php
mkdir("testing");
$filename = "one.html";
$content = file($filename);
$fp = fopen($filename,"w");
fclose($fp);
?>

I feel that I am not making myself clear. I want to create a folder in this php tag and in the folder I want one.html to go in it. What am I doing wrong? Thanks for the help.

Upvotes: 1

Views: 48

Answers (1)

Prasanth
Prasanth

Reputation: 5258

<?php
if(!is_dir("testing"))
    mkdir("testing");
$filename = "testing/one.html";
$content = "some text";
file_put_contents($filename, $content);
?>

should work. See file_put_contents

Upvotes: 5

Related Questions