跟ASP版一样在表单提交后进行处理!代码如下::)
$cttype = ii_get_num($_POST['cttype']); $saveimg = ii_get_num($_POST['saveimg']); if ($saveimg == 1 && $cttype == 0) { $tcontent = stripslashes(ii_left(ii_cstr($_POST['content']), 100000)); $img_array = array(); preg_match_all("/(src|SRC)=["|'| ]{0,}(http://(.*).(gif|jpg|jpeg|bmp|png))/isU",$tcontent,$img_array); $img_array = array_unique($img_array[2]); set_time_limit(0); $imgUrl = $nsaveimgdir."/".strftime("%Y%m/%d",time()); $imgPath = $imgUrl; $milliSecond = strftime("%H%M%S",time()); if(!ii_mkdir($imgPath)) @mkdir($imgPath,0777); foreach($img_array as $key =>$value) { $value = trim($value); $get_file = @file_get_contents($value); $rndFileName = $imgPath."/".$milliSecond.$key.".".substr($value,-3,3); $fileurl = $imgUrl."/".$milliSecond.$key.".".substr($value,-3,3); if($get_file) { $fp = @fopen($rndFileName,"w"); @fwrite($fp,$get_file); @fclose($fp); } $tcontent = ereg_replace($value,$fileurl,$tcontent); } $tcontent = addslashes($tcontent); } else { $tcontent = ii_left(ii_cstr($_POST['content']), 100000); }
帖子被 apje 于 2008-07-21 20:35:11 编辑过 |