diff --git a/class.php b/class.php index 16d3878..92c02b0 100644 --- a/class.php +++ b/class.php @@ -86,22 +86,56 @@ class ps4 { $sql = "UPDATE game_thumbnail SET thumbnail_url = '".$url."' WHERE game_id = '".$gameid."';"; } + if (($url == "") or ($url == "null")) { - echo "ERROR: No URL specified."; - echo "

"; + echo "
ERROR
No URL specified.
"; } else { - $result = $this->mysql_conn($sql); - if ($result == 1) { - echo "SUCCESS: Updated image URL for ". $gamename ." (". $gameid .")"; - echo "

"; + if ($this->isImage($url)) { + $result = $this->mysql_conn($sql); + if ($result == 1) { + echo "
SUCCESS
Updated image URL for ". $gamename ." (". $gameid .")
"; + } else { + echo "
ERROR
Can't update image URL for ". $gamename ." (". $gameid .")
"; + } } else { - echo "ERROR: Can't update image URL for ". $gamename ." (". $gameid .")"; - echo "

"; + echo "
ERROR
Not an image.
"; } } } + function isImage($url) + { + $params = array('http' => array( + 'method' => 'HEAD' + )); + $ctx = stream_context_create($params); + $fp = @fopen($url, 'rb', false, $ctx); + if (!$fp) + return false; // Problem with url + + $meta = stream_get_meta_data($fp); + if ($meta === false) + { + fclose($fp); + return false; // Problem reading data from url + } + + $wrapper_data = $meta["wrapper_data"]; + if(is_array($wrapper_data)){ + foreach(array_keys($wrapper_data) as $hh){ + if (substr($wrapper_data[$hh], 0, 19) == "Content-Type: image") // strlen("Content-Type: image") == 19 + { + fclose($fp); + return true; + } + } + } + + fclose($fp); + return false; + } + function games_reorder($games,$orderby="last_played_desc") { function totaltime_asc($a,$b) { return ($a["game_total_time"] <= $b["game_total_time"]) ? -1 : 1;