require_once 'simple_html_dom.php';
ini_set('memory_limit', '500M');
set_time_limit(0);
$url = "https://makita-line.ru";
function getCurlResult ($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLPROTO_HTTPS,1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$htmltext = curl_exec($ch);
curl_close($ch);
$htmltext = iconv("CP1251", "UTF-8", $htmltext);
if (strlen($htmltext) == 0) {
echo "пустой curl, url:" , $url;
}
return $htmltext;
}
function get_image_name($src) {
$arr_src = explode("/", $src);
$image_name = end($arr_src);
$image_name = str_replace("thumb", "full", $image_name);
return $image_name;
}
$file = fopen("/var/www/docs/lobochkin.ru/test/file.txt", "w");
$zz = 0;
$html = str_get_html(getCurlResult($url));
$html_arr = $html->find('.moduletable .mainlevel');// каталог верхнего уровня
foreach ($html_arr as $a) {
$item_name = $a->title;
$link = $a->href;
$url1 = $url . $link;
$html1 = str_get_html(getCurlResult($url1)); //каталог первого уровня
$html_arr1 = $html1->find('.sublevel');
if (count($html_arr1)) {// проверка на вложенность каталогов
foreach ($html_arr1 as $a1) {
$item_name1 = $a1->title;
$link1 = $a1->href;
$url2 = $url . $link1;
// echo $link1, " ", $item_name1, "<br>";
$html2= str_get_html(getCurlResult($url2)); //каталог второго уровня
$html_arr3 = $html2->find('.cat_div_t');
if (count($html_arr3)) {// проверка на вложенность каталогов
foreach ($html_arr3 as $div) {
$item_name2 = $div->find('a', 0)->title;
$link2 = $div->find('a', 0)->href;
$url3 = $url . $link2;
$html3= str_get_html(getCurlResult($url3)); //каталог третьего уровня
$html_arr4 = $html3->find('.cat_div_t');
if (count($html_arr4)) {// проверка на вложенность каталогов
foreach ($html_arr4 as $div1) {
$item_name3 = $div1->find('a', 0)->title;
$link3 = $div1->find('a', 0)->href;
$url4 = $url . $link3;
$html4= str_get_html(getCurlResult($url4)); //каталог четвертого уровня
$html_arr4 = $html4->find('.cat_div_t');
if (count($html_arr4)) {// проверка на вложенность каталогов
foreach ($html_arr4 as $div2) {
$item_name4 = $div2->find('a', 0)->title;
$link4 = $div2->find('a', 0)->href;
$url5 = $url . $link4;
$html5= str_get_html(getCurlResult($url5)); //каталог пятого уровня
echo (count($html5->find('.cat_div_t'))?"<h1>есть каталоги шестого уровня</h1>":"");
$html_arr6 = $html5->find('.items_catalog_one_item');
foreach ($html_arr6 as $a6) {
$product_name4 = $a6->find('.items_catalog_one_item_header h3 a', 0)->title;
$src4 = $a6->find('img', 1)->src;
$image_name4 = get_image_name($src4);
$characteristic4 = "";
$characteristic4 = ($i4 = $a6->find('.d_desc', 0))? $i4->innertext: "null";
preg_match_all('/<span>(.+?)<\/span>/', $characteristic4, $m4);
$characteristic_string4 = '';
foreach ($m[1] as $span4) {
$characteristic_string4 .= $span4 . "<br>";
}
// include "/var/www/docs/system/mycreset.phtml";
// mysqli_query($mysqllink, "call SYSTEM_NewInstrum2('Makita', '".$item_name."', '".$item_name1."', '".$item_name2."', '".$item_name3."', '".$item_name4."', '".$product_name4."', '".$image_name4."', '".$characteristic_string4."');"); ClearRecordsets();
$str = '';
$str = $item_name . "---" . $item_name1 . "---" . $item_name2 . "---" . $item_name3 . "---". $item_name4 . "---" . $product_name4 . "---" . $image_name4 . "---" . $characteristic_string4 . "\n" ;
fwrite($file, $str);
echo $item_name , "---" , $item_name1 , "---" , $item_name2 , "---" , $item_name3 , "---" ,$item_name4 , "---" , $product_name4 , "---" , $image_name4 , "---" , $characteristic_string4 , "<br>";
}
$html5->clear(); // подчищаем за собой
unset($html5);
}
} else {
$html_arr5 = $html4->find('.items_catalog_one_item');
foreach ($html_arr5 as $a5) {
$product_name3 = $a5->find('.items_catalog_one_item_header h3 a', 0)->title;
$src3 = $a5->find('img', 1)->src;
$image_name3 = get_image_name($src3);
$characteristic3 = "";
$characteristic3 = ($i3 = $a5->find('.d_desc', 0))? $i3->innertext: "null";
preg_match_all('/<span>(.+?)<\/span>/', $characteristic3, $m3);
$characteristic_string3 = '';
foreach ($m3[1] as $span3) {
$characteristic_string3 .= $span3 . "<br>";
}
// include "/var/www/docs/system/mycreset.phtml";
// mysqli_query($mysqllink, "call SYSTEM_NewInstrum2('Makita', '".$item_name."', '".$item_name1."', '".$item_name2."', '".$item_name3."', '', '".$product_name3."', '".$image_name3."', '".$characteristic_string3."');"); ClearRecordsets();
$str = '';
$str = $item_name . "---" . $item_name1 . "---" . $item_name2 . "---" . $item_name3 . "---" . $product_name3 . "---" . $image_name3 . $characteristic_string3 . "\n" ;
fwrite($file, $str);
echo $item_name , "---" , $item_name1 , "---" , $item_name2 , "---" , $item_name3 , "---" , $product_name3 , "---" , $image_name3 , "---" , $characteristic_string3 , "<br>";
}
}
$html4->clear(); // подчищаем за собой
unset($html4);
}
} else {
$html_arr5 = $html3->find('.items_catalog_one_item');
foreach ($html_arr5 as $a4) {
$product_name2 = $a4->find('.items_catalog_one_item_header h3 a', 0)->title;
$src2 = $a4->find('img', 1)->src;
$image_name2 = get_image_name($src2);
$characteristic2 = "";
$characteristic2 = ($i2 = $a4->find('.d_desc', 0))? $i2->innertext: "null";
preg_match_all('/<span>(.+?)<\/span>/', $characteristic2, $m2);
$characteristic_string2 = '';
foreach ($m2[1] as $span2) {
$characteristic_string2 .= $span2 . "<br>";
}
// include "/var/www/docs/system/mycreset.phtml";
// mysqli_query($mysqllink, "call SYSTEM_NewInstrum2('Makita', '".$item_name."', '".$item_name1."', '".$item_name2."', '', '', '".$product_name2."', '".$image_name2."', '".$characteristic_string2."');"); ClearRecordsets();
$str = '';
$str = $item_name . "---" . $item_name1 . "---" . $item_name2 . "---" . $product_name2 . "---" . $image_name2 . $characteristic_string2 . "\n" ;
fwrite($file, $str);
echo $item_name , "---" , $item_name1 , "---" , $item_name2 , "---" , $product_name2 , "---" , $image_name2 , $characteristic_string2 , "<br>";
}
}
$html3->clear(); // подчищаем за собой
unset($html3);
}
} else {
$html_arr2 = $html2->find('.items_catalog_one_item');
foreach ($html_arr2 as $a3) {
$product_name1 = $a3->find('.items_catalog_one_item_header h3 a', 0)->title;
$src1 = $a3->find('img', 1)->src;
$image_name1 = get_image_name($src1);
$characteristic1 = "";
$characteristic1 = ($i1 = $a3->find('.d_desc', 0))? $i1->innertext: "null";
preg_match_all('/<span>(.+?)<\/span>/', $characteristic1, $m1);
$characteristic_string1 = '';
foreach ($m1[1] as $span1) {
$characteristic_string1 .= $span1 . "<br>";
}
// include "/var/www/docs/system/mycreset.phtml";
// mysqli_query($mysqllink, "call SYSTEM_NewInstrum2('Makita', '".$item_name."', '".$item_name1."', '', '', '', '".$product_name1."', '".$image_name1."', '".$characteristic_string1."');"); ClearRecordsets();
$str = '';
$str = $item_name . "---" . $item_name1 . "---" . $product_name1 . "---" . $image_name1 . $characteristic_string1 . "\n" ;
fwrite($file, $str);
echo $item_name , "---" , $item_name1 , "---" , $product_name1 , "---" , $image_name1 , $characteristic_string1 , "<br>";
}
}
$html2->clear(); // подчищаем за собой
unset($html2);
}
} else {
$html_arr_p1 = $html1->find('.items_catalog_one_item');
foreach ($html_arr_p1 as $a2) {
$product_name = $a2->find('.items_catalog_one_item_header h3 a', 0)->title;
$src = $a2->find('img', 1)->src;
$image_name = get_image_name($src);
$characteristic = "";
$characteristic = ($i = $a2->find('.d_desc', 0))? $i->innertext: "null";
preg_match_all('/<span>(.+?)<\/span>/', $characteristic, $m);
$characteristic_string = '';
foreach ($m[1] as $span) {
$characteristic_string .= $span . "<br>";
}
// include "/var/www/docs/system/mycreset.phtml";
// mysqli_query($mysqllink, "call SYSTEM_NewInstrum2('Makita', '".$item_name."', '', '', '', '', '".$product_name."', '".$image_name."', '".$characteristic_string."');"); ClearRecordsets();
$str = '';
$str = $item_name . "---" . $product_name . "---" . $image_name . $characteristic_string . "\n" ;
fwrite($file, $str);
echo $item_name , "---" , $product_name , "---" , $image_name , "---" , $characteristic_string , "<br>";
}
}
$html1->clear(); // подчищаем за собой
unset($html1);
}
$html->clear(); // подчищаем за собой
unset($html);
fclose($file);
$html_arr_p1 = $html1->find('.items_catalog_one_item');
foreach ($html_arr_p1 as $a2) {
$product_name = $a2->find('.items_catalog_one_item_header h3 a', 0)->title;
$src = $a2->find('img', 1)->src;
$image_name = get_image_name($src);
$characteristic = "";
$characteristic = $a2->find('.product_short_info_parametr', 0)->find('span');
$characteristic_string = '';
foreach ($m[1] as $span) {
$characteristic_string .= $span->plaintext . "<br>";
}
$str = '';
$str = $item_name . "---" . $product_name . "---" . $image_name . "\n" ;
fwrite($file, $str);
echo $item_name , "---" , $product_name , "---" , $image_name , "---" , $characteristic_string , "<br>";
}
Array ( ) Array ( [foo] => barf [file_contents] => @/var/www/docs/lobochkin.ru/test/j.jpg )
$url = "http://lobochkin.ru/test/upload_output.php";
$cFile = "/var/www/docs/lobochkin.ru/test/j.jpg";
$post_data = array (
"foo" => "barf",
// файл для загрузки
"file_contents" => "@" . $cFile
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
$output = curl_exec($ch);
echo(curl_error($ch));
curl_close($ch);
echo $output;
<?php
echo "<pre>";
print_r( $_POST );
print_r( $_FILES );
echo "</pre>";
?>
<form action="" method="post" enctype="multipart/form-data" >
<input type="file" name="image">
<input type="submit" name="ok" value="Отправить">
</form>