Ê

Search Help Board

PHP FAQ
PHP Articles
PHP Help
Bulletin Board

PHP Manual (NEW!)
First Time PHP'ers
Help with programming
Sql assignment help
PHP Homework Help


C# Help

Ê
ÊFile Creation Problemas
Author:ÊÊ(---.93.2.infovia.com.ar)
Date:ÊÊÊ06-04-03 11:59

Hi

I am new in PHP and I have two problems.

1.- I don’t know how can I create a file via PHP. I know modified, delete and move, but I don’t know how can I create a file in the disk via PHP.

2.- How can I pass-through the user and group when I am creating it.

Thank

ÊRe: File Creation Problemas
Author:ÊÊ(---.dmisinetworks.com)
Date:ÊÊÊ06-04-03 13:33

There is a fundamental problem with file creation in PHP. PHP uses the group "httpd" and there is no way to change the group/user when creating this file.

Here is a simple way to write a new file on the disk.

$filename = 'test.txt';
$somecontent = "Add this to the file\n";

if (is_writable($filename))
{
$handle = fopen($filename, 'a');
fwrite($handle, $somecontent);

print "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);

} else {
print "The file $filename is not writable";
}
?>

ÊRe: File Creation Problemas
Author:ÊÊ(---.splitrock.net)
Date:ÊÊÊ06-04-03 21:20

Change the permissions on your directory to allow to write to it, then the following will work.

if(!file_exists($fileName))
{
$file_handle = fopen($fileName, 'w');
fwrite($file_handle, "Text to put in file.");
}

ÊRe: File Creation Problemas
Author:ÊÊ(---.93.2.infovia.com.ar)
Date:ÊÊÊ06-13-03 06:58

Good,

Thank a lot,

I use that you tell me and work, but if I change the directory permission I have a security hold?

I note that my FTP change the permission via a UNIX command (chmod).

Can I execute an UNIX command via PHP?

Another time, Thank a lot guys.

JR

ÊRe: File Creation Problemas
Author:ÊÊ(---.93.2.infovia.com.ar)
Date:ÊÊÊ06-13-03 06:58

Good,

Thank a lot,

I use that you tell me and work, but if I change the directory permission I have a security hold?

I note that my FTP change the permission via a UNIX command (chmod).

Can I execute an UNIX command via PHP?

Another time, Thank a lot guys.

JR

ÊRe: File Creation Problemas
Author:ÊÊ(---.dmisinetworks.com)
Date:ÊÊÊ06-13-03 10:56

You can exec any system command through php by using the system() function ... like ...

// Ping A Host
system("ping www.google.com");
?>

Go to TopÊÊ|ÊÊGo to TopicÊÊ|ÊÊThreaded ViewÊÊ|ÊÊSearchÊ
ÊÊ|ÊÊ
New Topic
ÊReply To This Message
ÊYour Name:
ÊYour Email:
ÊSubject:
Email replies to this thread, to the address above.
ÊÊ

Provided By
Phorum