NYCPHP Meetup

NYPHP.org

[nycphp-talk] phantom file writing errors

Marc Antony Vose suzerain at suzerain.com
Tue Jul 27 01:07:15 EDT 2004


Hi:

To John:

It's creating directories inside a directory that is chmod 777.  Into 
each directory is placed an HTML file, which is created in the code 
below.  Therefore, all of the directories and files involved are 
owned by the script that is being run (user: apache, grp: apache), 
since the files didn't even exist in the first place.  And it's 
definitely writing to the file, because the contents of the files are 
there.

To inforequest:

Could you explain what you mean by 'file-handle-passed' problem?

Here's the relevant code, which goes through an array of films, reads 
in a template file, and writes out an HTML file containing the list 
of distributors for the film:

----+

// step through the films array and output the file
for( $x=0; $x<count($all_films); $x++ ){


//....snip snip: a few setup variables

// MAIN_ROOT, in this case = $_SERVER['DOCUMENT_ROOT']

// the directory name is the film_id
$output_dir = MAIN_ROOT . '/_admin/distributors/output/' . 
$all_films[$x]["film_id"];
// the file name
$output_file = 'distributors.html';
// build the path, for convenience
$output_path = $output_dir . "/" . $output_file;

// create the directory, if necessary
if( !file_exists($output_dir) && !is_dir($output_dir) ){
	mkdir($output_dir,0755);
}

//...snip snip: the code that populates the variable $output

// output the file
$output_h = fopen($output_path,"w");
fwrite($output_h,$output);
fclose($output_h);


//...snip snip: code that copies the file to a remote server


}

----+

Anything crazy in there?



At 12:22 AM -0400 7/27/04, inforequest wrote:
>This is often a file-handle-passed problem. Show us the the code 
>where you assign $output_path, and why not $output as well to be 
>thorough.
>
>
>
>Marc Antony Vose suzerain-at-suzerain.com |nyphp 04/2004| wrote:
>
>>Hi there:
>>
>>Can anyone tell my why I would get this error:
>>
>>Warning: fwrite(): supplied argument is not a valid stream resource 
>>in Warning: fclose(): supplied argument is not a valid stream 
>>resource in
>>when the script is in fact opening and writing out the file just fine?
>>
>>here's my file handling calls, just for reference:
>>
>>// output the file
>>$output_h = fopen($output_path,"w");
>>fwrite($output_h,$output);
>>fclose($output_h);
>>
>>
>>This is happening on a new server I just moved to, and doesn't 
>>happen on my old server, nor did it happen on my old server.  Must 
>>be some kind of configuration thing...
>>
>>--
>>
>>Marc Antony Vose
>>http://www.suzerain.com/
>>
>>They that can give up essential liberty to obtain a little 
>>temporary safety deserve neither liberty nor safety.
>>-- Benjamin Franklin
>>
>>------------------------------------------------------------------------
>>
>>_______________________________________________
>>New York PHP Talk
>>Supporting AMP Technology (Apache/MySQL/PHP)
>>http://lists.nyphp.org/mailman/listinfo/talk
>>http://www.newyorkphp.org
>>
>
>_______________________________________________
>New York PHP Talk
>Supporting AMP Technology (Apache/MySQL/PHP)
>http://lists.nyphp.org/mailman/listinfo/talk
>http://www.newyorkphp.org




More information about the talk mailing list