首页上一页 1 下一页尾页 1 条记录 1/1页
这段代码哪里出错了,咋写入不了??
发表在PHP图书答疑
2010-11-05
是否精华
是
否
版块置顶:
是
否
del这部分的可以,下面save那部分不行。。帮忙看看哪里出错了
<?php
}elseif ($_GET['mod']=="del"){
$sid=$_GET['sid'];
$file='../adjs/'.$id.'.js';
$filewrite = fopen($file,'w');
if($filewrite){ fwrite($filewrite, ""); }
fclose($filewrite);
echo"<script>alert('成功清除选定广告代码,请继续!');location.href='admin_ad.php?mod=list';</script>";
}elseif ($_GET['mod']=="save"){
//读取原数据并进行缓存
$adcode = file_get_contents('../inc/ad.php');
$adcode = str_replace('ks_ad','ks_nad',$adcode);
$filewrite = fopen('../cache/ad.txt','w');
if($filewrite){ fwrite($filewrite, $adcode); }
fclose($filewrite);
//读取缓存数据
include '../cache/ad.txt';
//更改广告信息
$ks_nad_name[$id]=$_POST['ks_ad_name'];
$ks_nad_size[$id]=$_POST['ks_ad_size'];
$ks_ad_code='<?php '."\r\n";
$ks_ad_code=$ks_ad_code.'$ks_ad_num="'.$ks_nad_num.'"'.";\n\r";
for ($i=1;$i<=$pt_ad_num;$i++){
$ks_ad_code=$ks_ad_code.'$ks_ad_name['.$i.']="'.$ks_nad_name[$i].'"'.";\n\r";
$ks_ad_code=$ks_ad_code.'$ks_ad_size['.$i.']="'.$ks_nad_size[$i].'"'.";\n\r\n\r";
}
$ks_ad_code=$ks_ad_code.'?>';
//写入新数据
$file='../inc/ad.php';
$filewrite = fopen($file,'w');
if($filewrite){ fwrite($filewrite, $ks_ad_code); }
fclose($filewrite);
//html转js
$jscode=$_POST['ks_ad_code'];
$jscode=str_replace('/','\/',$jscode);
$jscode=str_replace('\"','"',$jscode);
$jscode=str_replace('"','\"',$jscode);
$jscode=str_replace("\'","'",$jscode);
$jscode=str_replace("'","\'",$jscode);
$jscode= split("\r\n",$jscode);
for($i=0;$i<count($jscode);$i++)
{
$jsadcode.= "document.writeln(\"".$jscode[$i]."\");\r\n";
}
//写入js
$file='../adjs/'.$id.'.js';
$filewrite = fopen($file,'w');
if($filewrite){ fwrite($filewrite, $jsadcode); }
fclose($filewrite);
echo"<script>alert('修改成功!');location.href='admin_ad.php?mod=list';</script>";
}
<?php
}elseif ($_GET['mod']=="del"){
$sid=$_GET['sid'];
$file='../adjs/'.$id.'.js';
$filewrite = fopen($file,'w');
if($filewrite){ fwrite($filewrite, ""); }
fclose($filewrite);
echo"<script>alert('成功清除选定广告代码,请继续!');location.href='admin_ad.php?mod=list';</script>";
}elseif ($_GET['mod']=="save"){
//读取原数据并进行缓存
$adcode = file_get_contents('../inc/ad.php');
$adcode = str_replace('ks_ad','ks_nad',$adcode);
$filewrite = fopen('../cache/ad.txt','w');
if($filewrite){ fwrite($filewrite, $adcode); }
fclose($filewrite);
//读取缓存数据
include '../cache/ad.txt';
//更改广告信息
$ks_nad_name[$id]=$_POST['ks_ad_name'];
$ks_nad_size[$id]=$_POST['ks_ad_size'];
$ks_ad_code='<?php '."\r\n";
$ks_ad_code=$ks_ad_code.'$ks_ad_num="'.$ks_nad_num.'"'.";\n\r";
for ($i=1;$i<=$pt_ad_num;$i++){
$ks_ad_code=$ks_ad_code.'$ks_ad_name['.$i.']="'.$ks_nad_name[$i].'"'.";\n\r";
$ks_ad_code=$ks_ad_code.'$ks_ad_size['.$i.']="'.$ks_nad_size[$i].'"'.";\n\r\n\r";
}
$ks_ad_code=$ks_ad_code.'?>';
//写入新数据
$file='../inc/ad.php';
$filewrite = fopen($file,'w');
if($filewrite){ fwrite($filewrite, $ks_ad_code); }
fclose($filewrite);
//html转js
$jscode=$_POST['ks_ad_code'];
$jscode=str_replace('/','\/',$jscode);
$jscode=str_replace('\"','"',$jscode);
$jscode=str_replace('"','\"',$jscode);
$jscode=str_replace("\'","'",$jscode);
$jscode=str_replace("'","\'",$jscode);
$jscode= split("\r\n",$jscode);
for($i=0;$i<count($jscode);$i++)
{
$jsadcode.= "document.writeln(\"".$jscode[$i]."\");\r\n";
}
//写入js
$file='../adjs/'.$id.'.js';
$filewrite = fopen($file,'w');
if($filewrite){ fwrite($filewrite, $jsadcode); }
fclose($filewrite);
echo"<script>alert('修改成功!');location.href='admin_ad.php?mod=list';</script>";
}