This article to give you some of the commonly used PHP to extract the pictures in the article, and replace, move the image directory code, I hope this article will be helpful to everyone.
Upload pictures, uploaded images are not all used, then you can set the upload only to the temporary folder inside, the article released when the real use of the pictures moved to a useful directory, so regularly clean up the useless directory can be.
The code is as follows |
Copy Code |
Transfer pictures from a temporary folder $imgssss = Preg_match_all ("/linshi/[^s", "]+.jpg|png|gif|jpeg{1}/ui", $content, $IMGSS); $i = 1; foreach ($imgss as $aimg) { if (is_string ($aimg)) { if (file_exists ($aimg)) { $newdir = "upload/". Date ("Ymdhis"). " /"; if (!file_exists ($newdir)) { mkdir ($newdir, 0755,true); } $newname = $newdir. Date ("Ymdhis"). $i. ".". PathInfo ($aimg, pathinfo_extension); Rename ($aimg, $newname); $content = Str_replace ($aimg, $newname, $content); } $i + +; }elseif (Is_array ($aimg)) { foreach ($aimg as $imga) { if (file_exists ($IMGA)) { $newdir = "upload/". Date ("Ymdhis"). " /"; if (!file_exists ($newdir)) { mkdir ($newdir, 0755,true); } $newname = $newdir. Date ("Ymdhis"). $i. ".". PathInfo ($imga, pathinfo_extension); Rename ($imga, $newname); $content = Str_replace ($imga, $newname, $content); } $i + +; } } } |
If you just move a single Picture it's easier:
The code is as follows |
Copy Code |
$newdir = "upload/". Date ("Ymdhis"). " /"; if (!file_exists ($newdir)) { mkdir ($newdir, 0755,true); } $newname = $newdir. " S_ ". Date (" Ymdhis ").". ". PathInfo ($upimgurl, pathinfo_extension); Rename ($upimgurl, $newname); |
http://www.bkjia.com/PHPjc/631500.html www.bkjia.com true http://www.bkjia.com/PHPjc/631500.html techarticle This article to give you some of the commonly used PHP to extract the pictures in the article, and replace, move the image directory code, I hope this article will be helpful to everyone. Upload images, upload ...