服务报价 | 域名主机 | 网络营销 | 软件工具| [加入收藏]
 热线电话: #
当前位置: 主页 > php教程 > php教程 >

PHP实现发表文章时自动保存图片

时间:2016-02-10 10:54来源: 作者: 点击:
PHP实现发表文章时自动保存图片 ?php $img_array = array(); $content1 = stripslashes($content1); if (get_magic_quotes_gpc()) $content1 = stripslashes($content1); //echo $content1; preg_match_all(/(src│SRC)=(http://(. ).(gif│jp
PHP实现发表文章时自动保存图片
<?php 
 
$img_array = array(); 
 
$content1 = stripslashes($content1); 
 
if (get_magic_quotes_gpc()) $content1 = stripslashes($content1); 
 
//echo $content1; 
 
preg_match_all("/(src│SRC)="(http://(. ).(gif│jpg│jpeg│bmp│png))/isU",$content1,$img_array); 
 
$img_array = array_unique(dhtmlspecialchars($img_array[2])); 
 
set_time_limit(0); 
 
foreach ($img_array as $key => $value) { 
 
$get_file = file_get_contents($value); 
 
$filetime = time(); 
 
$filepath = "../uploadfile/".date("Y",$filetime)."/".date("m",$filetime)."/"; 
 
!is_dir($filepath) ? mkdirs($filepath) : null; 
 
$filename = date("YmdHis",$filetime).random(1).'.'.substr($value,-3,3); 
 
$fp = @fopen($filepath.$filename,"w"); 
 
@fwrite($fp,$get_file); 
 
fclose($fp); 
 
$content1 = preg_replace("/".addcslashes($value,"/")."/isU", "/uploadfile/".date("Y",$filetime)."/".date("m",$filetime)."/".$filename, $content1); 
 
?> 
(责任编辑:最模板)
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------