Php fopen nasıl kullanılır () doğru

2 Cevap

I am learning php, trying to use the fopen() function. The php file I am coding is in this directory /domains/xxxxx.com.au/public_html/phpfile.php What path do I specify for the file to be opened, the example I am looking at is based on a server on a pc where this is the file path $filename = "c:/newfile.txt"; not an online server.

GÜNCELLEME!

Bu bütün script, ben dosya konuma doğru var, şimdi the4 komut bu dosyanın klasör konumu orada izni ile ilgili bir şey var "dosyası oluşturun olamazdı" dönüyor?

   <?php
$filename = "/domains/xxxxxxxx.com.au/public_html/newfile.txt";
$newfile = @fopen($filename, "w+") or die ("couldnt create the file");
fclose($newfile);
$msg = "<p>File Created</p>";
?>

<HTML>
<HEAD>
</HEAD>
<BODY>

<? echo "$msg" ?>

</BODY>
</HTML>

2 Cevap

Php dosya çok public_html içinde olduğunu varsayarsak, kullanabilirsiniz:

$fp = fopen( "newfile.txt", "rt" );

Veya, tam yol vererek:

$fp = fopen( "/domains/xxxxx.com.au/public_html/newfile.txt", "rt" );

Zaten varsa bu açacağız.

Bayrakları açılması daha detaylı bilgi için this bakınız.

UPDATE: You can even use the is_writable/is_readable function to check file access before trying to open it.

http://us2.php.net/manual/en/function.fopen.php Örnek 1 Unix sistem için uygun olduğunu okuyun.