Alex Alex - 1 year ago 88
PHP Question

Creating a php file using php File Write

I tried to create a php file and save it in a root directory but it give error while doing it

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE),
expecting identifier (T_STRING) or variable (T_VARIABLE) or number
(T_NUM_STRING) in C:\xampp\htdocs\page\cjl\configAlter.php on line 181

here is my code

$IndexFile = 'default.php';
$IndexCont = "<?php
$currentBas = basename(dirname(__FILE__));
$parentBas = basename(dirname(dirname($_SERVER['SCRIPT_NAME'])));//Line 181
$DIR = __DIR__;
//This is already define $parentDir."".$SubFolderjailorgname
$fileDirectoryR = $parentDir."".$SubFolderjailorgname;
$myReadfile = fopen($fileDirectoryR.'/'.$IndexFile, "w") or die("Failed to open file!");
fwrite($myReadfile, $IndexCont);

Answer Source

Using double quotes " means your $_SERVER becomes evaluated in the $IndexCont string.

If you didn't mean it to be evaluated, use single quotes.

If you did need it evaluated, the resulting value in the string would be a syntax error when that new file is loaded, try adding single quotes around it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download