NYCPHP Meetup

NYPHP.org

[nycphp-talk] phantom file writing errors

Sol sol2ray at yahoo.fr
Tue Jul 27 10:28:11 EDT 2004


> // 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
> 
> 
> }
> 

If you have an invalid filename character in
$all_films[$x]["film_id"] it will fail.

e.g:
if($all_films[$x]["film_id"] == ' '){
   you will get this:
   $output_dir.'/ /distributors.html'
  
  so this will pass:
  if( !file_exists($output_dir) &&
 !is_dir($output_dir) ){
 	mkdir($output_dir,0755);
 }

 but this will fail:
   
$output_h = fopen($output_path,"w");
 fwrite($output_h,$output);
 fclose($output_h);

}


=====
Sol Touré
PHPBTREE
http://phpbtree.com


		
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail 



More information about the talk mailing list