ZengCode.Com (The Thai Php Framework)  


Home   Download   Manual   About us    

Facebook   


MAIN MENU
News
Php Tips
Spring+Strut+Hibernate
Android Programming
Design Pattern By PHP
Ubuntu
Linux Quick Tips
C# Design Pattern
C# using Linq น่าใช้จริงๆ
C# Tips & Technique
Java & JavaScript Tips
Database & SQL
ZengCode Framework Guide
Zeng Code Code
Programming
IPhone (Tips and Trick)

Download เอกสารที่น่าสนใจ

     PHP กับการ อ่านเขียน Text Files อย่างง่ายๆ  (2009-02-12)

พอดีมีเพื่อนท่านนึงให้ช่วย เห็นว่าน่าจะมีประโยชน์สำหรับผู้เริ่มต้นบางท่าน

<?php
$path     = "";          //ระบุ path ถ้าไฟล์อยู่ใน path เดียวกับไฟล์นี้ไม่ต้องใส่ก็ได้
$file_name = "MyLogFile.txt"; //ชื่อไฟล์
$filename     = $path.$file_name;

Echo "Working with ==>  ".$filename;

if ($_POST)
{
   Write_File($filename,$_POST['contents']);
}

$str = Read_File($filename);
?>

<form method="post">
<textarea name="contents" cols="100" rows="10"><?=$str?></textarea>
<br><input type="submit" value="Overwrite This File" onclick="return confirm('Do you want to overwrite this file');">
</form>





<?
//=====================File Manupulation Function======================//

function Write_File($filename,$content)
{
    if (is_writable($filename)) {

    if (!$handle = fopen($filename, 'w+')) {
         echo "<br><font color='red' size='3'>Cannot open file ($filename)</font><BR>";
         exit;
    }
    
     if (fwrite($handle, $content) === FALSE) {
        echo "<br><font color='red' size='3'>Cannot write to file ($filename)</font><BR>";
        exit;
    }

    echo "<br><font color='green' size='3'>Overwrite $filename is Successful</font><BR>";


    fclose($handle);
} else {
    echo "<br><font color='red' size='3'>The file $filename is not writable</font><BR>";
}
}

function Read_File($filename)
{  
    $handle = fopen($filename, "r");
     if (filesize($filename)) $contents = fread($handle, filesize($filename));
    fclose($handle);
    return $contents;
}

?>


Comment

narm  (13 มีนาคม 2552)   
IP : 58.9.26.169

เพื่อนผมเก่ง มากครับ โค๊ด โอเคเลย ลองแล้ว เสียดายเมาเก่งไปหน่อย



เก่ง  (13 มีนาคม 2552)   
IP : 210.4.138.40

สุดยอดมากเพื่อนกู สู้ต่อไปบนทางที่มึงฝันนะ
กูเชื่อว่ามึงทำได้ อย่าท้อแท้กลางทาง อุปสรรค์มีไว้ให้พัฒนาตัวมึงเอง
สู้ต่อไปไอ้หมอกระเด็น



dekub  (12 มีนาคม 2552)   
IP : 124.122.149.142

บทความดีมากเลยครับ กำลังต้องการใช้อยู่พอดี


Name
Comment
Security CodeCAPTCHA Image

web hit counter

This page took 0.058890 seconds to load.