NYCPHP Meetup

NYPHP.org

[nycphp-talk] Sorry, really stupid question...

Adam Fields fields at surgam.net
Sat Dec 28 16:01:10 EST 2002


On Sat, Dec 28, 2002 at 03:34:40PM -0500, Phil Powell wrote:
> "Have the file chmoded"...
> 
> You completely lost me.  How can I chmod a file I have not yet opened?

chmod() is a standalone function, and not part of the stream
read/write set. You don't have to have the file open to use it. It's
as if you called chmod directly from the shell.

You do, however, need to supply it a full path.

You may need to use fflush, if you run into buffering issues. Under
normal conditions, you shouldn't have to. You can explicitly use
stream_set_write_buffer to configure your stream for no buffering, but
again, unless you have a good reason to do so, you shouldn't.

> Phil
> ----- Original Message -----
> From: "Analysis & Solutions" <danielc at analysisandsolutions.com>
> To: "NYPHP Talk" <talk at nyphp.org>
> Sent: Saturday, December 28, 2002 2:56 PM
> Subject: Re: [nycphp-talk] Sorry, really stupid question...
> 
> 
> > On Sat, Dec 28, 2002 at 02:26:29PM -0500, Phil Powell wrote:
> >
> > > $fileID = fopen("nicknames.txt", "a") or die("Could not open " . $path .
> "/nicknames.txt");
> > >    chmod("nicknames.txt", 0755);
> > >    fputs($fileID, $nickname . "\
"); fflush($fileID); fclose($fileID);
> >
> > Let's rewrite this in more efficient, readable code...
> >    $File = '/path/to/nicknames.txt';
> >    $fileID = fopen($File, 'a') or die("Could not open $File");
> >    fputs($fileID, "$nickname\
");
> >
> > Key changes...
> >    * Have the file chmoded in the first place, not every time you open it
> >      up, nor while you have it open already.
> >    * Changed double quotes to single quotes in fopen statement.  Double
> >      quotes only needed when strings are evaluated (have variables in
> >      them).
> >    * fflush() isn't needed at all.
> >    * fclose() happens automatically when the script ends, so is
> >      only helpful when you have a long script.
> >
> > --Dan
> >
> > --
> >                PHP classes that make web design easier
> >     SqlSolution.info  | LayoutSolution.info |  FormSolution.info
> >  T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
> >  4015 7th Ave #4AJ, Brooklyn NY    v: 718-854-0335   f: 718-854-0409
> >
> >
> > 
> >
> >
> 
> 
> 
> --- Unsubscribe at http://nyphp.org/list/ ---
> 
> 

-- 
				- Adam

-----
Adam Fields, Managing Partner, fields at surgam.net
Surgam, Inc. is a technology consulting firm with strong background in
delivering scalable and robust enterprise web and IT applications.
http://www.adamfields.com



More information about the talk mailing list