PHP file_put_contents() İşlev
❮ PHP Dosya Sistemi ReferansıÖrnek
Bir dosyaya veri yazın:
<?php
echo file_put_contents("test.txt","Hello World. Testing!");
?>
Yukarıdaki kodun çıktısı şöyle olacaktır:
21
Tanım ve Kullanım
file_put_contents(), verileri bir dosyaya yazar.
Bu işlev, bir dosyaya erişirken şu kuralları izler:
- FILE_USE_INCLUDE_PATH ayarlanmışsa, dosya adının bir kopyası için dahil etme yolunu kontrol edin
- Dosya yoksa oluşturun
- Dosyayı aç
- LOCK_EX ayarlanmışsa dosyayı kilitleyin
- FILE_APPEND ayarlanmışsa, dosyanın sonuna gidin. Aksi takdirde, dosya içeriğini temizleyin
- Verileri dosyaya yazın
- Dosyayı kapatın ve tüm kilitleri serbest bırakın
Not: Dosyanın mevcut içeriğini silmekten kaçınmak için FILE_APPEND kullanın.
Sözdizimi
file_put_contents(filename, data, mode, context)
Parametre Değerleri
Parameter | Description |
---|---|
filename | Required. Specifies the path to the file to write to. If the file does not exist, this function will create one |
data | Required. The data to write to the file. Can be a string, array, or a data stream |
mode | Optional. Specifies how to open/write to the file. Possible values:
|
context | Optional. Specifies the context of the file handle. Context is a set of options that can modify the behavior of a stream. |
Teknik detaylar
Geri dönüş değeri: | Başarı durumunda dosyaya yazılan bayt sayısı, başarısızlık durumunda FALSE |
---|---|
PHP Sürümü: | 5.0+ |
İkili Kasa: | Evet |
PHP Değişiklik Günlüğü: | PHP 5.1 - LOCK_EX desteği ve veri parametresine bir akış kaynağı geçirme yeteneği eklendi |
❮ PHP Dosya Sistemi Referansı