国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 建站經驗 > 正文

php實現編輯和保存文件的方法

2024-04-25 20:39:41
字體:
來源:轉載
供稿:網友

本文實例講述了php實現編輯和保存文件的方法。分享給大家供大家參考。具體如下:

save_file.php:

<?php

session_start();

$handle = fopen($_POST['original_file_name'], "w");

$text = $_POST['file_contents'];

if(fwrite($handle, $text) == FALSE){

$_SESSION['error'] = '<span class="redtxt">There was an error</span>';

}else{

$_SESSION['error'] = '<span class="redtxt">File edited successfully</span>';

}

fclose($handle);

header("Location: ".$_POST['page']);

?>

read_file.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

<form action="savecontents.php" method="post">

<textarea name="file_contents" style="width:700px;height:600px;">

<?php

$fileName = "location/of/orignal/file/my_file.php";

$handle = fopen($fileName, "r");

while (!feof($handle)){

$text = fgets($handle);

echo $text;

}

?>

</textarea>

<input type="hidden" value=" <? echo $fileName; ?> " name="original_file_name" />

</form>

<body>

</body>

</html>

希望本文所述對大家的php程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 盐亭县| 垦利县| 广南县| 乌海市| 江达县| 封开县| 南通市| 军事| 天气| 玉环县| 望城县| 英吉沙县| 思茅市| 南京市| 洪湖市| 武冈市| 榕江县| 子长县| 西吉县| 东城区| 陆川县| 双鸭山市| 武川县| 资兴市| 井陉县| 周宁县| 阳城县| 会泽县| 绥芬河市| 祁连县| 桐城市| 宜丰县| 新蔡县| 巴中市| 策勒县| 南丹县| 化州市| 耿马| 松滋市| 凤翔县| 抚州市|