PHP file Action-read the database file path copy to another directory ____php

Source: Internet
Author: User
Tags create directory file separator preg set time

PHP file Operations

Copy the database file path to another directory

Code:

<?php date_default_timezone_set (' Asia/shanghai ');
Set time zone $db _host = ' 127.0.0.1 ';
$db _name = ' Test_qyg_datas ';
$db _user = ' root ';
$db _pwd = ' xxx ';
$mysqli = new Mysqli ($db _host, $db _user, $db _pwd, $db _name);

$mysqli->set_charset ("UTF8"); $sql _array = Array (' Select image from Buser_goods_list where Image <> ' ORDER by bid ', ' Select image from Suppl Ier_buser_goods_list where Image <> "ORDER by bid ', ' SELECT image from Works_sku where Image <> '
Y id ', ' SELECT image from Supplier_works_sku where Image <> ' ORDER by ID '; $fs = Directory_separator;
File Separator $root = "{$fs}data{$fs}www{$fs}test";
$root _CP = "{$fs}data{$fs}www{$fs}IMG_CP";

$log = ' Log.log '; foreach ($sql _array as $key => $value) {file_put_contents ($log, date (' y-m-d h:i:s ').
	"Query sql: $value \ r \ n", file_append);
	$result = $mysqli->query ($value); if ($result = = False) {file_put_contents ($log, date (' y-m-d h:i:s ').
		"SQLERROR Query SQL failed: $value \ r \ n", file_append);Continue

			try{while ($row = $result->fetch_assoc ()) {if Empty ($row [' image ']) continue;
			$images = Explode (', ', $row [' image ']); foreach ($images as $k => $img) {if (Stripos ($img, ' http ')!== false) {//File path contains http $preg = '/^ (http:\/\ /? [^\/]+)/I ';
					Matching HTTP domain name regular preg_match ($preg, $img, $res);
				$img = Str_replace ($res [0], $img); } if (!file_exists ($root. $img)) {file_put_contents ($log, date (' y-m-d h:i:s ').
					"ERROR file does not exist: $img \ r \ n", file_append);
				Continue
				$img _index = Strripos ($img, '/') + 1;
				$folder = substr ($img, 0, $img _index);
				$file = substr ($img, $img _index); $root _cp_tmp = $root _cp.

				$folder; Determine if the folder exists if (!file_exists ($root _cp_tmp)) {$res = mkdir (Iconv ("UTF-8", "GBK", $root _cp_tmp), 0777, true);//Create The folder if ($res = = True) {file_put_contents ($log, date (' y-m-d h:i:s ').
					"TRUE to create a directory: $root _cp_tmp\r\n", file_append); }else{file_put_contents ($log, date (' YM-d h:i:s ').
						"ERROR Create directory failed: $root _cp_tmp\r\n", file_append);
					Continue
				}//Execute Copy File command exec ("CP $root $img $root _cp_tmp", $result _info); if (Empty ($result _info)) {file_put_contents ($log, date (' y-m-d h:i:s ').
				"TRUE replication success: $img \ r \ n", file_append); }else{file_put_contents ($log, date (' y-m-d h:i:s '). "ERROR Replication failed:". Json_encode ($result _info).
				"File: $img \ r \ n", file_append); }}}catch (Exception $e) {file_put_contents ($log, date (' y-m-d h:i:s '). "Syserror an error:". $e->getmessage ().
	"\ r \ n", file_append); }

}


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.