Vinothkumar Nataraj
Vinothkumar Nataraj

Reputation: 588

How to create one file and data store in php?

$myFile = "folder1/folder2/order.txt";
$fh = fopen($myFile, 'a');fwrite($fh, $Message);
    fclose($fh);

I am use this code.But file is not create in that particular folder

Upvotes: 0

Views: 75

Answers (1)

Imran
Imran

Reputation: 4750

Try this:

<?php 
$myFile = "folder1/folder2/order.txt";
$fh = fopen($myFile, 'a'); or die("Unable to open the file");
fwrite($fh, $Message);
fclose($fh);
?>

If this code shows "Unable to open the file" that means there is something wrong while opening the file. This may happen if the folder1/folder2 doesn't exist. Or may be you are not permitted to open a file to write on that folder. If you are in Linux you can change the permission of you directory like this:

chmod 777 folder/folder2

Upvotes: 1

Related Questions