PHP is extracting the pictures from the article and replacing and moving the picture Catalog _php Tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.