FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Cannot create file





fladry
I tried to create a file using php and it will display a error
The php code is

<?
$ourFileName = "testFile.txt";
$fh = fopen($ourFileName, 'w');
fclose($fh);
?>

It says that the function doesnot has enough permission
Star Wars Fanatic
fladry wrote:
I tried to create a file using php and it will display a error
The php code is

<?
$ourFileName = "testFile.txt";
$fh = fopen($ourFileName, 'w');
fclose($fh);
?>

It says that the function does not has enough permission


You need to set the permissions of the php file to I think 755, but if that doesn't work, try 777.
You can set the files permissions from either a ftp program, or from the admin panel of the server.
fladry
both didn't worked
sonam
I think you need to write something in this file. I am not sure can you create one empty txt file.

Code:
<?
$ourFileName = "testFile.txt";
$fh = fopen($ourFileName, 'wb');
$content = "Some content";
fwrite($fh, $content);
fclose($fh);
?>


Sonam
kv
You haven't specified any path for the file. So it should be trying to write file in the script directory, which may not have write access to the user which is running php (apache).

Make sure you provide a directory which is writable by webserver.
Agent ME
Make the file yourself where you want it, and chmod it properly.

Or if you need the script to be able to make new files (such as for logging things), you need to chmod the directory itself.
fladry
Thank you all for help. The problem was with CHMOD setting in my public_html directory. I fixed it. And at last also, thank you all
jmraker
Changing the permissions of an important directory so anyone can write to it could be exploited by others.

The reason why the script can't create the file is because it's executed by the web server which is running as a different user that usually can't edit and delete files created by others (you included). By setting the /public_html directory's permission to 777, or allowing read/write/execute to all 3 groups, everyone can read/write every file in that directory, programs can be edited/deleted/created

The better solution is to create a subdirectory just for files to be created, uploaded file, set it's permission to 777 and use the directory in fopen, as in fopen('datafiles/testFile.txt', 'wb');
Related topics
[phpbb] clone styles with "extreme styles mod"
php image exif functions
.htacess in phpBB ?
SUPER FLASH STORE {CLOSED}
PHP VS ASP
.htaccess
File upload problem :'(
Need help: Error in Wordpress file
Copy file script
Cannot create / save files
i cannot create database in frih
Delete An "undeletable" File
Cannot Create Triggers in MySQL at Frihost
delete and create
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.