PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php // Директория куда будут сохранятся изображения. $path = $_SERVER["DOCUMENT_ROOT"] . "/db/tips"; // Загружать или нет изображения с других доменов. $external = true; $url_send = 'https://www.sqlstyle.guide/ru/'; if (file_exists($url_send)) { $html = file_get_contents($url_send); if ( preg_match_all( '/<img.*?src=["\'](.*?)["\'].*?>/i', $html, $images, PREG_SET_ORDER ) ) { $url_send = parse_url($url_send); $path = rtrim($path, "/"); foreach ($images as $image) { if (strpos($image[1], "data:image/") !== false) { continue; } if (substr($image[1], 0, 2) == "//") { $image[1] = "http:" . $image[1]; } $ext = strtolower(substr(strrchr($image[1], "."), 1)); if (in_array($ext, ["jpg", "jpeg", "png", "gif"])) { $img = parse_url($image[1]); // Если файл уже существует if (is_file($path . $img["path"])) { continue; } $path_img = $path . "/" . dirname($img["path"]); if (!is_dir($path_img)) { mkdir($path_img, 0777, true); } if (empty($img["host"]) && !empty($img["path"])) { copy( $url_send["scheme"] . "://" . $url_send["host"] . $url_send["path"], $path . $img["path"] ); } elseif ( $external || ($external == false && $img["host"] == $url_send["host"]) ) { copy($image[1], $path . $img["path"]); } } } } $command = Yii::app()->db->createCommand(); $command->insert("db_items", [ "img" => $image[1], "item_id" => $item, ]); echo "<pre>"; echo "Saved:--->" . $item . ""; } else { echo "Not exists: $url_send"; } file_put_contents("db/tips/" . $item . ".html", $response);
Show:  
Copy Clear