Location: PHPKode > projects > TVEz - Media Library > tvez-0.2.1/html/admin/image_lib.php
<?php

# ------------------------------------------------------------------------------
#
# Contains all the php image functionality
#
# ------------------------------------------------------------------------------
#
# Copyright (C) 2003 Christian Eheim and Alex Pachikov
#
# This file is part of TVEz (tvez.sourceforge.net).
#
# TVEz is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# TVEz is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with TVEz; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# ------------------------------------------------------------------------------
#
# Created on 12/07/2003 by Christian Eheim (hide@address.com)
#
# LAST MODIFIED:
# $Date: 2004/01/11 23:20:46 $
# $Revision: 1.1.1.1 $
# $Author: eheim $
#
# ------------------------------------------------------------------------------

################################################################################
# This function removes images for a given movie id
################################################################################
function remove_images($id) {
	require "../config/config_file.php";

	$sdel = $ldel = true;
	if ($spath = find_image("$IMG_PATH/small", $id))
		$sdel = unlink($spath);
	if ($lpath = find_image("$IMG_PATH/large", $id))
		$ldel = unlink($lpath);

	return ( $sdel & $ldel );
}

################################################################################
# Gets the image path of a movie id in a directory
################################################################################
function find_image($dir,$id) {
	if ($dh = opendir($dir)) {
		# Find the file with the given id
		while ($file = readdir($dh)) {
		   if ( preg_match("/$id\.*/",$file) ) {
				closedir($dh);
				return "$dir/$file";
		   }
		}
		closedir($dh);
	}
	return false;
}

################################################################################
# Retrieves an image from the web
################################################################################
function retrieve_image($img,$dir,$id) {
	$img = preg_replace("/http:\/\//","",$img);	
	list($host,$img) = split("/", $img, 2);

	$image = http_request($host,80,15,"/$img");

	$ai = split("\.", $img);
	$filename = $dir."/".$id.".".end($ai);

	# Amzon send a GIF if the image does not exist
	if ( preg_match("/GIF89a/i", $image) && ! preg_match("/gif/i", end($ai)) )
		return;

	$fp = fopen($filename,"w");
	if ($fp) {
		fwrite($fp,$image);
		fclose($fp);
		chmod($filename,0666);
	}
	else exit_error(localize_string("Could not save the image").".");
}

?>
Return current item: TVEz - Media Library