Page 1 of 1

Getting all images from a cargo collective page php regex

Posted: Wed Jul 24, 2013 3:22 am
by darknkreepy3#
My clients have tons of photos in their galleries. They never saved them to folders for me. "It's on the site". Great, I should sit there and copy 500~800 pics by hand and organize them? No. Cargo Collective blocks their users from having an FTP access to their images (it's a simple template script, they don't even know how to do that safely anyway)... so...
Seems that the javascript calls some images in a database so it is needed to go to the page, copy source html as it was loaded, paste it in the right side, and then you can get them. I can figure out something else later. (more expressions!)
1. Make a form
2. Add the addy of the cargo single gallery page (yes for each)
3. get the html with php and get_contents(#2 addy above);
4. spit it to another php page for regular expression stripping for src_o original image

Next to do:
1. program to make a new folder locally per gallery via MySQL and PHP
2. copy the images into the new folder with GD2 for resizing (or just copy and paste from cargo)

cargo_extract.php

Code: Select all

<?php
	/*
	cargo_extract.php v1.0 by Kristoffe Brodeur. ©2013 All Rights Reserved.
	07-23-2013	Initial version to enter a cargo gallery page and see it's conents
				Then send it to cargo_getimgs.php as $_POST['rawData'] for regular expression processing
	*/
	$tgt="";
	$rawStr="";
	$title="";
	//
	if(isset($_POST['tgt']))
		{
		$tgt=$_POST['tgt'];
		$rawStr=file_get_contents($tgt);
		$exp1='/([^\/]*)$/';
		preg_match($exp1,$tgt,$ttl);
		$title=$ttl[0];
		}
?>
<html>
	<head>
		<link type="text/css" rel="stylesheet" href="cargoRaw.css" />
	</head>
	
	<body>
		<div id="formArea">
			<form name="cargoPage" method="POST" action="cargo_extract.php">
				<h3>Cargo Gallery Page</h3>
				<input name="tgt" size="120"><br>
				<input type="submit" value="get html">
			</form>
		</div>
		<div id="htmlData">
		<h3><?php echo $tgt;?></h3>
			<form name="extractImg" method="POST" action="cargo_getimgs.php">
				<input name="title" size="120" value="<?php echo $title;?>"><br>
				<textarea name="rawData" id="rawData" cols="120" rows="40"><?php echo $rawStr;?></textarea>
				<input type="submit" value="get imgs">
		</div>
	</body>
</html>
cargo_getimgs.php

Code: Select all

<?php
	/*
	cargo_getimgs.php v1.0 by Kristoffe Brodeur. ©2013 All Rights Reserved.
	07-23-2013	Initial version with rawData sent from cargo_extract.php
				Just the html get_contents of a cargo page
	*/
	$rawData="";
	//
	if(isset($_POST['rawData']))
		{
		$rawData=$_POST['rawData'];
		}
	//
	$exp1='/<img src="http:[^>]+>/i';
	preg_match_all($exp1,$rawData,$imgArr);
	$len=count($imgArr[0]);
	echo "<h3>image count [$len]</h3>";
	$outStr="";
	$outImg="";
	//
	for($a=1;$a<$len;$a++)
		{
		$exp2='/src_o="?([^"\']*)/i';
		preg_match($exp2,$imgArr[0][$a],$imgO);
		//
		if(isset($imgO[1]))
			{
			$outStr.=$imgO[1]."\r";
			$outImg.="
				<img src='".$imgO[1]."' width='200px' />";
			}
		}
	//
?>

<textarea rows="4" cols="120"><?php echo $outStr;?></textarea>
<hr />
<?php echo $outImg;?>