Problem writing to a file (php)

Chris S

Retired
Messages
2,055
Reaction score
1
Points
38
Last edited:

Torch

New Member
Messages
634
Reaction score
0
Points
0
It's not that '=' is added, the problem is that none of your variables are getting transfered, because script is trying to print their value instead of them as string. And since they have no value, nothing is printed and transfered to new file.

I fixed your code, haven't tested it, but I think it should work:
PHP:
<?php 
$filename = "countdown2.php"; 

$somecontent = '<?php

header("Content-type: image/png");
   $image = imagecreatefrompng("../away.png");

      $red = imagecolorallocate($image, 255, 000, 000); 
      $green = imagecolorallocate($image, 000, 100, 000); 
      $black = imagecolorallocate($image, 000, 000, 000); 
   
   imageline($image, 1, 1, 1, 199, $black); 
   imageline($image, 1, 1, 199, 1, $black); 
   imageline($image, 1, 74, 199, 74, $black); 
   imageline($image, 199, 1, 199, 74, $black); 
$font = "../larabieb.ttf";

function countdown($year, $month, $day, $hour, $minute, $image, $font, $color) 
{ 
  $the_countdown_date = mktime($hour, $minute, 0, $month, $day, $year, -1); 

  $today = time(); 

  $difference = $the_countdown_date - $today; 
  if ($difference < 0) $difference = 0; 

  $event = "Come Home from Europe\nand Homecoming Performence"; //event

  $days_left = floor($difference/60/60/24); 
  $hours_left = floor(($difference - $days_left*60*60*24)/60/60); 
  $minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60); 
   
    imagettftext($image, 10.1, 0, 5, 15, $black, $font, "Event:$event");
    imagettftext($image, 10.1, 0, 5, 50, $black, $font, "Days Until I Come Back:$days_left");

  } 

countdown(2006,7,19,5,0, $image, $font, $color); 


imagepng($image); 

imagedestroy($image); 
?>';
   if (!$handle = fopen($filename, 'w')) { 
         echo "Cannot open file ($filename)"; 
         exit; 
   } 

   // Write $somecontent to our opened file. 
   if (fwrite($handle, $somecontent) === FALSE) { 
       echo "Cannot write to file ($filename)"; 
       exit; 
   } 
   
   echo "Success"; 
   
   fclose($handle); 

?>
This is replace.php file
 
Last edited:
Top