加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 20:38:38 所属栏目: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,$i
  1. <?php 
  2.  
  3. $img_array = array(); 
  4.  
  5. $content1 = stripslashes($content1); 
  6.  
  7. if (get_magic_quotes_gpc()) $content1 = stripslashes($content1); 
  8.  
  9. //echo $content1; 
  10.  
  11. preg_match_all("/(src│SRC)="(http://(. ).(gif│jpg│jpeg│bmp│png))/isU",$content1,$img_array); 
  12.  
  13. $img_array = array_unique(dhtmlspecialchars($img_array[2])); 
  14.  
  15. set_time_limit(0); 
  16.  
  17. foreach ($img_array as $key => $value) { 
  18.  
  19. $get_file = file_get_contents($value); 
  20.  
  21. $filetime = time(); 
  22.  
  23. $filepath = "../uploadfile/".date("Y",$filetime)."/".date("m",$filetime)."/"
  24.  
  25. !is_dir($filepath) ? mkdirs($filepath) : null; 
  26.  
  27. $filename = date("YmdHis",$filetime).random(1).'.'.substr($value,-3,3); 
  28.  
  29. $fp = @fopen($filepath.$filename,"w"); 
  30.  
  31. @fwrite($fp,$get_file); 
  32.  
  33. fclose($fp); 
  34.  
  35. $content1 = preg_replace("/".addcslashes($value,"/")."/isU""/uploadfile/".date("Y",$filetime)."/".$filename$content1); 
  36.  
  37. ?> 

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读