Unable to create a file

saeed

Verified User
Joined
Oct 7, 2003
Messages
26
Location
Riyadh
//////////////////
$content='<?php
$db_host="'.$mhost.'";
$db_name="'.$dname.'";
$db_user="'.$duname.'";
$db_pass="'.$dpass.'";
?>';

$file=@fopen("global.php","w");
@fputs($file,$content);
@fclose($file);
///////////////////

I tired this code one of my cpanel machine; its working fine I am able to create a file.

Whereas i have tried the same code in Directadmin machine; its not working; its not creating global.php file.

I donno what to do.... Do i have to set some permission?
 
Hello,

Yes, php files are run as apache, but the directory is owned by your username.. so if you want to write a file, you'll need to chmod the file to 777.

John
 
There is no file before; I want to generate file "global.php" at runtime.

For which file i have to change the mod. You mean for global.php.
Its not created yet how can i change untill it not create.
 
Hello,

You can either chmod 777 the whole directory that the file is in, or else create an empty global.php with 777. Apache cannot create a file in a directory that's owned by someone else without settings 777 somewhere ;)

John
 
Back
Top