Page 1 of 1

how to make php create files

Posted: Wed Feb 12, 2003 8:09 am
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?

Posted: Wed Feb 12, 2003 8:33 am
by lazy_yogi
try replace
touch($filename);

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