Php (Create File) Issues

Hey,

I’m currently having the following problem. I want to create a folder and put a file into it. The issues I’m having is as follows.

I have successfully created the folder…

<?php mkdir($row_GetUserData['username'],0777,TRUE); ?>

How is it that I can stick a file inside of that folder? But inside of the new folder designated by the ‘username’. I’m having a mental block currently and its killing me.

Thanks

Case 1: You want to create a file inside the directory
touch() function -> http://www.w3schools.com/php/func_filesystem_touch.asp (Don’t forget to read the ‘Note’ which says “Note: If the specified file does not exist, it will be created.”)

Case 2: You want to move uploaded file to that directory
move_uploaded_file ( string $filename , string $destination )
http://php.net/manual/en/function.move-uploaded-file.php

Hey, I’ve done this before, and looking back through my websites I found this.
It might help, hope its what your after.

[php] $var = ’ blah blah '; // What to put in file
$file = “pages/”.$filename.".php"; // file to write to
$openfile = fopen("$file",“a”); // a appends to the end of file
fwrite($openfile,"$var\n"); // Create it and write to it
fclose($openfile); // close it all[/php]

Creates a .php file names $filename.php in the folder pages/
What file are you wanting to create?

Sponsor our Newsletter | Privacy Policy | Terms of Service