[insert_php]

global $wpdb;

$brain_id = $_GET[‘brain_id’];
$label = $_GET[‘label’];

$results = $wpdb->get_results(“SELECT Navigator_section.jp2Image FROM Navigator_section WHERE Navigator_section.brain_id=$brain_id AND Navigator_section.label=’$label’ AND Navigator_section.isDamaged=0 AND Navigator_section.reImage=0 ORDER BY Navigator_section.slideIndex ASC”);

$new_images = array();
if ($results) {
foreach ($results as $row) {
$new_images[] = $row->jp2Image;
}
}
$path = wp_upload_dir();
$count = 0;
foreach($new_images as $image) {
$image_link = explode(‘||’, $image);
$less_image = explode(‘.jp2′,$image_link[0]);
if($label ==’F’){
$remote_img = $less_image[0].’.jp2&WID=150&QLT=130&CNT=2&CVT=jpeg’;
$img = imagecreatefromjpeg($remote_img);
$path = wp_upload_dir();
save_image($img, $path[‘basedir’].’/testing/’);
echo $remote_img.’|’.$path[‘basedir’].’/testing/
‘;

$image_link = $less_image[0].’.jp2′;
$split_image = pathinfo($image_link);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL , $image_link);
curl_setopt($ch, CURLOPT_USERAGENT, “Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13”);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response= curl_exec($ch);
curl_close($ch);

$file_name = $path[‘basedir’].’/testing/’.$split_image[‘filename’].’.’.$split_image[‘extension’];
echo $file_name.’
‘;
$file = fopen($file_name , ‘w’) or die(“X_x”);
fwrite($file, $response);
fclose($file);
}else{

}
$count = $count + 1;
}

[/insert_php]
function save_image($img,$fullpath){
$ch = curl_init ($img);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata=curl_exec($ch);
curl_close ($ch);
if(file_exists($fullpath)){
unlink($fullpath);
}
$fp = fopen($fullpath,’x’);
fwrite($fp, $rawdata);
fclose($fp);
}

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *