I need to create an ImageIcon from an image on a remote server. When I loaded it with a URL like \[code\]http://www.server.com/1.png\[/code\] it worked fine.But recently the server was changed so that the images are stored outside of web root and must be accessed with something like \[code\]http://www.server.com/get_image.php?id=1\[/code\], where get_image.php outputs the correct headers to serve the image. When I create an ImageIcon with that type of URL, it fails to load without throwing any exceptions and getImageLoadStatus() returns MediaTracker.ERRORED. The image serving script works fine from a browser.Any ideas on how could I make this work?Thanks.Edit: Here's the Java code.\[code\]ImageIcon labelIcon = new ImageIcon(new URL(IMAGE_URL));
System.out.println(labelIcon.getImageLoadStatus());\[/code\]I also tried the following, but it didn't work either.\[code\]ImageIcon labelIcon = new ImageIcon();
BufferedImage image = ImageIO.read(new URL(IMAGE_URL));
labelIcon.setImage(image);\[/code\]Edit: Here's the code from get_image.php. $DB is an object included from global.php that is used to interact with a MySQL database. I've verified that the MIME type being returned is image/png.\[code\]<?php if (isset($_GET['uid'])) { require_once('./include/global.php'); getUpload(intval($_GET['uid'])); } function getUpload($id) { global $DB; $query = "SELECT `name`, `mime_type` FROM `uploads` WHERE `id` = " . $id . " LIMIT 1"; $arrUpload = $DB->getSingleRecord($query); if (count($arrUpload) > 0) { $file = UPLOADS_ROOT . $arrUpload['name']; header("Content-type: " . $arrUpload['mime_type']); header("Content-Disposition: filename=" . $arrUpload['name']); readfile($file); } else { header("HTTP/1.1 404 Not Found"); } die(); }?>\[/code\]
System.out.println(labelIcon.getImageLoadStatus());\[/code\]I also tried the following, but it didn't work either.\[code\]ImageIcon labelIcon = new ImageIcon();
BufferedImage image = ImageIO.read(new URL(IMAGE_URL));
labelIcon.setImage(image);\[/code\]Edit: Here's the code from get_image.php. $DB is an object included from global.php that is used to interact with a MySQL database. I've verified that the MIME type being returned is image/png.\[code\]<?php if (isset($_GET['uid'])) { require_once('./include/global.php'); getUpload(intval($_GET['uid'])); } function getUpload($id) { global $DB; $query = "SELECT `name`, `mime_type` FROM `uploads` WHERE `id` = " . $id . " LIMIT 1"; $arrUpload = $DB->getSingleRecord($query); if (count($arrUpload) > 0) { $file = UPLOADS_ROOT . $arrUpload['name']; header("Content-type: " . $arrUpload['mime_type']); header("Content-Disposition: filename=" . $arrUpload['name']); readfile($file); } else { header("HTTP/1.1 404 Not Found"); } die(); }?>\[/code\]