Jump to content

How to Create a file, then write to it?


benphp

Recommended Posts

I can use this code to write to an EXISTING file, but when I try to use it to CREATE a file, it fails - or rather, it doesn't do anything - not even throwing an error. What am I doing wrong?

 

<?php
$path = "";
$filename = "myfile.txt";
$fp = fopen($path.$filename, 'w') or die("Sorry charlie"); 
flock($fp, LOCK_EX);
fwrite($fp, "I like almonds");
flock($fp, LOCK_UN);
fclose($fp);
?>

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/104409-how-to-create-a-file-then-write-to-it/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.