首页 > 开发 > PHP > 正文

PHP发表文章时自动保存图片实例代码

2024-05-04 21:52:55
字体:
来源:转载
供稿:网友
  1. img_array = array(); 
  2. content1 = stripslashes(content1); 
  3. if (get_magic_quotes_gpc()) content1 = stripslashes(content1); 
  4. //echo content1; 
  5. preg_match_all("/(src│SRC)="(http://(.+).(gif│jpg│jpeg│bmp│png))/isU",content1,img_array); 
  6. img_array = array_unique(dhtmlspecialchars(img_array[2])); 
  7. set_time_limit(0); 
  8. foreach (img_array as key => value) { 
  9. get_file = file_get_contents(value); 
  10. filetime = time(); 
  11. filepath = "../uploadfile/".date("Y",filetime)."/".date("m",filetime)."/"
  12. !is_dir(filepath) ? mkdirs(filepath) : null; 
  13. filename = date("YmdHis",filetime).random(1).'.'.substr(value,-3,3); 
  14. fp = @fopen(filepath.filename,"w"); 
  15. @fwrite(fp,get_file); 
  16. fclose(fp); 
  17. content1 = preg_replace("/".addcslashes(value,"/")."/isU""/uploadfile/".date("Y",filetime)."/".date("m",filetime)."/".filename, content1); 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表