Skip to content

Instantly share code, notes, and snippets.

@tmbritton
Created July 26, 2012 15:22
Show Gist options
  • Save tmbritton/3182671 to your computer and use it in GitHub Desktop.
Save tmbritton/3182671 to your computer and use it in GitHub Desktop.
Attempt to get WKF images from web service
<?php
$db['hostname']='localhost';
$db['username']='root';
$db['password']='root';
$db['schema']='wkf_salad_map';
date_default_timezone_set('America/Chicago');
$path = 'wkfimages/';
if(!$link = mysqli_connect($db['hostname'], $db['username'], $db['password'])){
echo mysqli_errno($link) . ": " . mysqli_error($link) . "\n";
}
if(!mysqli_select_db($link, $db['schema'])){
echo mysqli_errno($link) . ": " . mysqli_error($link) . "\n";
}
$sql = 'SELECT id, grant_id FROM `map_info` WHERE grant_id IS NOT NULL LIMIT 5';
$url = 'http://www.gardengrantapplication.org/wkf-office/imageservlet?name=gardenPhotoAttachment&grantRequestId=';
if($result = mysqli_query($link, $sql)){
while($row = mysqli_fetch_array($result)) {
$id = $row['id'];
$grant = $row['grant_id'];
if($data = file_get_contents($url . $grant)){
echo 'File Info Obtained: ' . $id . ' ' . date(DATE_ATOM, time()) . "\n";
if($ih = imagecreatefromstring($data)){
echo $id . ': Valid Image File' . "\n";
if(imagejpeg($ih, $path . $id . '.jpg')){
echo 'Image Written: ' . $id . '.jpg, ' . date(DATE_ATOM, time()) . "\n\n";
} else {
echo 'Failed writing image: ' . $id . '.jpg, ' . date(DATE_ATOM, time()) . "\n\n";
}
} else {
echo $id . ': Not an image file' . "\n\n";
}
} else {
echo 'Failure Getting File Data: ' . $id . ' ' . $url . $grant . ' ' . date(DATE_ATOM, time()) . "\n\n";
}
sleep(1);
}
} else {
echo mysqli_errno($link) . ": " . mysqli_error($link) . "\n";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment