找回密码
 注册
搜索
热搜: 回贴
微赢网络技术论坛 门户 网络编程 PHP 查看内容

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

2009-12-21 17:50| 发布者: admin| 查看: 32| 评论: 0|原作者: 小可爱

$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);

最新评论

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-9-30 01:28 , Processed in 0.146199 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

返回顶部