15-09-2007, 15:31
|
|
|
חבר מתאריך: 09.09.07
הודעות: 8
|
|
ציטוט:
במקור נכתב על ידי Dark Knight
טוב, אין לי הרבה ידע על עבודה עם קבצים בכלל, וב-PHP בפרט, אז אני אתן לך תשובה בסיסית ש"תעשה את העבודה" ונקווה שחבר'ה עם קצת יותר ידע ממני יוכלו לשפר את העניין קצת...
נתחיל ממספר 1:
טוב, אז כעקרון העמוד שלך צריך להכיל תיבת טקסט (מן הסתם) לצורך העריכה.
אתה צריך לקרוא את הקובץ לתוך תיבת הטקסט ואז לכתוב את הטקסט בחזרה.
רק שים לב להרשאות של הקובץ!
קוד PHP:
<?php /* Although This code comes in the head of the page - it will, in fact, be executed last. */ if (isset($_POST['sub'])) { //If form was submit $handle = fopen('text.txt', 'w'); // Open file "text.txt" in local directory for OVERWRITE. Old content is deleted. if (!$handle) { echo "Faild to open file!"; exit; } // Check for successful opening! if (fwrite($handle, $_POST['txt']) === FALSE) { //Both writing the data and checking echo "Cannot write to file!"; exit; } echo "<font color='red'> Successfully modified the file!</font>"; // Notify the user that the operation was successful fclose($handle); // Release resources. } ?> <form action="" method="POST"> <textarea name="txt" rows=30 cols=100> <?php /* This Code will move the content of the file into the text area. * From this point, the user may modify this content * When user is done, he should hit "Submit" */ $file = fopen('text.txt', 'r'); // Open file "text.txt" in local directory for READ-ONLY. if (!$file) { echo "Faild to open file!"; exit; } // Check for successful opening! while (!feof($file)) { // While not reached the end of file $buffer = fgets($file, 4096); //Get Line echo $buffer; // Print the line into the text area. } fclose($file); // Release resources. ?> </textarea> <br><input type="submit" name="sub" value="Submit"> </form>
על העקרון הזה אתה יכול להלביש פונק' PHP שיעדכנו את הטקסט איך שאתה רוצה.
כל העקרון פה עובד על שכתוב של הקובץ.
אני לא ממש יודע איך אפשר לעדכן קובץ באמצע, אז את זה אשאיר לשאר החברים פה...
|
תודה רבה על הניסיון לעזור לי
אבל אין לי ידע בכלל בכתיבה למסמך טקסט עריכה וכולי אז אם מישהו יוכל לתת לי קוד מלא, וככה אני יבין הכי טוב..
תודה רבה.
|