-1

iam trying to over write a file in the yii web app the code is in the view file and i want to over write the a file inside the protected/config folder can u suggest me how to fopen ($file,'w');

I following is the code which i used

$my_file = '..\..\config\main2.php';
$file=fopen("..\..\config\main2.php","w");
fwrite($file, $str1.$str3.$str8.$str5.$str7);

the following error was thrown for m e

fopen(../../config/main.php) [function.fopen]: failed to open stream: No such file or directory

please can any one suggest how to use the the fopen in the yii webapp

zzlalani
  • 22,960
  • 16
  • 44
  • 73
DILLI
  • 1
  • 1
  • 7
  • There is a reason why you cant access config file like this.. And you shouldnt be tinkering with that.. It can truly compromise on ur security.. – Roy M J Nov 28 '13 at 07:27

4 Answers4

0

try this..

$my_file = '../../config/main2.php';
$file=fopen($my_file,"w");
fwrite($file, $str1.$str3.$str8.$str5.$str7);
Lekhesh
  • 35
  • 1
  • 9
0

I think you can't access files inside protected, because it's protected by .htaccess file

you may want to change deny from all

Developerium
  • 7,155
  • 5
  • 36
  • 56
0

I don't know what you want to do! But if you just want to update some configuration, you don't have to overwrite this file.

Every option in that file could be updated in controller or other place you like, including your view file!

Matthias
  • 3,582
  • 2
  • 30
  • 41
jiang
  • 170
  • 4
0

I think the filepath might be plain wrong. Try with the powers of dirname():

$file=fopen(dirname(__FILE__).'/../../config/main2.php');
fwrite($file,...);
DaSourcerer
  • 6,288
  • 5
  • 32
  • 55