How to move a picture file in bulk in PHP

Source: Internet
Author: User
Help for PHP Bulk move picture file method
I now have two PHP shopping sites, product categories are more, now I want the first site of the database part of the product transfer to the second site database, the picture will be moved out, I just want to iterate over and insert the database and move each product's picture from the product directory to another specified folder. How to operate, please help the experts. Thank you first.

------Solution--------------------
After you have queried the path to the picture, call the system command copy to copy the picture to the new path, and then insert the new path into the new database.
------Solution--------------------
This is to distinguish whether the movement of the picture is under the same server or under a different server
The same server can use the Rename function
Different servers to use depending on the environment settings
Copy unlink
File_get_contents file_put_contents Unlink
FTP Function Group

------Solution--------------------
discuss
This is to distinguish whether the movement of the picture is under the same server or under a different server

Different servers to use depending on the environment settings
Copy
------Solution--------------------

$conn 1=mysql_connect (******);//source Site Connection
$conn 2=mysql_connect (******);//target site Connection
$query =mysql_query ("SELECT * from ***********", $conn 1);
while ($rs = Mysql_fetch_array ($query)) {
$imgpath 1= "/web1/". $rs ("img");
$imgpath 2= "/web2/". $rs ("img");
Rename ($imgpath 1, $imgpath 2);//The same server, different servers need file_get_contents way to get pictures

$sql = "INSERT INTO tablename set";
$ext = "";
If you do not need to import the ID into the past, you can unset ($rs [' id ']), and then perform the following
foreach ($rs as $key = = $value) {
$sql. = $ext. " ' {$key} ' = ' {$value} ';
$ext = ",";
}
mysql_query ($sql, $conn 2);
}

That's probably it.
  • Related Article

    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.