Problems with file creation

This is a discussion on Problems with file creation within the PHP Language forums, part of the PHP Programming Forums category; Hello, I have been migrating my custom cms work towards a push system. My first step has been to make ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-01-2008
jerrygarciuh
 
Posts: n/a
Default Problems with file creation

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
Reply With Quote
  #2 (permalink)  
Old 02-01-2008
Jerry Stuckle
 
Posts: n/a
Default Re: Problems with file creation

jerrygarciuh wrote:
> 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
>


Usually because the PHP user doesn't have write authority on the directory.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:55 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0