how to make php create files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
DaZZleD
Forum Commoner
Posts: 38
Joined: Tue Jan 07, 2003 5:39 am

how to make php create files

Post by DaZZleD »

i can't seem to make php create files on the server (linux with apache 1.3). it acts as if it doesn't have the right to write the file. i use the following script:

Code: Select all

<?php
  function writedatatodisk($filename, $content)
  {
	if (file_exists($filename))
	{
	 $delete = @unlink($filename);
	}

	 touch($filename);
	 chmod($filename,0666);

	if (is_writable($filename))
	{
		if (!$fp = fopen($filename, 'a'))
		{
	        print "Cannot open file ($filename)";
	        exit;
		}
		if (!fwrite($fp, $content))
		{
			print "Cannot write to file ($filename)";
			exit;
		}
	   fclose($fp);

	} 
	else
	{
		print "The file $filename is not writable";
	}
  }
?>
on my winXP box home it worked just fine. on the server i uploaded it won't.
anyone can give me any clues?
User avatar
lazy_yogi
Forum Contributor
Posts: 243
Joined: Fri Jan 24, 2003 3:27 am

Post by lazy_yogi »

try replace
touch($filename);

with
$fp = fopen($filename , 'w');
fclose($fp);
Post Reply