PHP实现发表文章时自动保存图片
来源:程序员人生 发布时间:2014-06-14 14:07:59 阅读次数:3524次
- <?php
-
- $img_array = array();
-
- $content1 = stripslashes($content1);
-
- if (get_magic_quotes_gpc()) $content1 = stripslashes($content1);
-
-
-
- preg_match_all("/(src│SRC)="(http:
-
- $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);
-
- ?>
生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
------分隔线----------------------------
------分隔线----------------------------