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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.