Jump to content

[SOLVED] how to write php code to a file?


ballhogjoni

Recommended Posts

I want to write this code to a php file but when it does it excludes the variables

 

string written to the x.php file:

$stringData = "<?php";
		$stringData .= " include('../config.php');";
		$stringData .= "$oDB = new FACSDatabase();";
		$stringData .= "$rResult = $oDB->Select('".$aUploadImageInfo['db_table']."','".$aUploadImageInfo['db_data']."','".$aUploadImageInfo['db_where']."');";
		$stringData .= "while( $row = mysql_fetch_array( $rResult ) ){";
		$stringData .= "$article = '<div class=\'style15\'>'";
		$stringData .= ".$row[title].'</div><font size=\'2\' color=\'#999999\'>";
		$stringData .= "By '.$row[author].'</font><hr />'.$row[tinymcedata];";
		$stringData .= "}include('".$aUploadImageInfo['mainFile']."');";
		$stringData .= "?>";

 

code in the x.php file:

<?php include('../config.php'); = new FACSDatabase(); = ('Articles as a,Authors as au','a.*,au.*','WHERE a.article_id = '' AND a.author_id = au.author_id');while(  = mysql_fetch_array(  ) ){ = '<div class=\'style15\'>'..'</div><font size=\'2\' color=\'#999999\'>By '..'</font><hr />'.;}include('');?>

 

My question is how to I write this code to make php write all the variables and not replace them as nothing? Basically it looks like php is erasing my variables.

 

Here's the entire function:

function CreateUploadDirectoriesImages($aUploadImageInfo,$Files){
	$result = '';
	$filepath = '/home/xxx/www/xxx/'.$aUploadImageInfo['secondary_folder']."/".$aUploadImageInfo['article_folder_name'];
	if(!is_dir($filepath)) {
        	mkdir($filepath,0777);
        }
        if(!is_dir($filepath . 'images/')) {
        	mkdir($filepath . '/images/',0777);
        }
	if( !file_exists($filepath.'/index.php') ){
		$newFile = $filepath."/index.php";
		$fh = fopen($newFile, 'w') or die("can't create file");
		$stringData = "<?php";
		$stringData .= " include('../config.php');";
		$stringData .= "$oDB = new FACSDatabase();";
		$stringData .= "$rResult = $oDB->Select('".$aUploadImageInfo['db_table']."','".$aUploadImageInfo['db_data']."','".$aUploadImageInfo['db_where']."');";
		$stringData .= "while( $row = mysql_fetch_array( $rResult ) ){";
		$stringData .= "$article = '<div class=\'style15\'>'";
		$stringData .= ".$row[title].'</div><font size=\'2\' color=\'#999999\'>";
		$stringData .= "By '.$row[author].'</font><hr />'.$row[tinymcedata];";
		$stringData .= "}include('".$aUploadImageInfo['mainFile']."');";
		$stringData .= "?>";
		fwrite($fh, $stringData);
		fclose($fh);
	}
	$filepath = $filepath.'/images/'.basename( $Files['name']); 
	if(move_uploaded_file($Files['tmp_name'], $filepath)) {
		$result = "The file ".basename( $Files['name'])." has been uploaded";
	}else{
		$result = "There was an error uploading the file, please try again!";
	}
	return $result;
}

Link to comment
https://forums.phpfreaks.com/topic/120743-solved-how-to-write-php-code-to-a-file/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.