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