You are here: Problems with file creation « PHP Programming Language « IT news, forums, messages
Problems with file creation

Posted by jerrygarciuh on 02/01/08 17:00

Hello,

I have been migrating my custom cms work towards a push system. My
first step has been to make all navigation into static files that are
written when the site structure is changed via the cms.

Thing is I have had to resort to having a dummy file in place and use
copy() on it to create my new files. This is less elegant than I
would like but I find that fopen($filename, 'w') fails to create a
file where none exists on a lot of servers.

On one insecure *nix server where passthru was enabled I also tried

if (!file_exists($pgNavFile)) {
passthru("touch $pgNavFile");
}

but it failed silently.

My preferred route would be for the function below to work every
time. Can anyone tell me why the w flag does not work on all servers?

TIA

jg

function writeMenu($filename, $somecontent) {
$msg = 'Navigation updating...';
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'w')) {
$msg .= " Cannot open file ($filename). ";
}
// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
$msg .= " Cannot write to file ($filename). ";
}
fclose($handle);
$msg .= " Success, updated file: $filename. ";
} else {
$msg .= " The file $filename is not writable. ";
}
return $msg;
} // func

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация