thumbnail creator problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
utinaeniduin
Forum Newbie
Posts: 4
Joined: Thu Aug 30, 2007 11:16 pm

thumbnail creator problems

Post by utinaeniduin »

I have been looking for a simple bit of code that will allow me to use any image already uploaded and resize it down to a small thumbnail. I have found a lot, but this code seems to be as closest to what I want.

Code: Select all

// Get image info from variable
	$url = $_GET['url'];
	$img = getimagesize($url);//line 7
	
	// Checks if URL is image
	if ( $img[2] == 1 ) {
		$pic = imagecreatefromgif( $url ) or die();
	} elseif ( $img[2] == 2 ) {
		$pic = imagecreatefromjpeg( $url ) or die();
	} elseif ( $img[2] ==3 ) {
		$pic = imagecreatefrompng( $url ) or die();
	} else {exit();}
	
	
	// If an image is found and we can determine that it is an image
	if ($pic) {
		// Get width and height from the image
		$width = imagesx($pic);
		$height = imagesy($pic);
		$theight = 100;
		
		// Calculate the new width
		$twidth = ($theight * $width) / $height;
	
		// Create new image
		$thumb = @imagecreatetruecolor ( $twidth, $theight )
		or die ("Can't create Image!");
	
		// Resize the image into a thumb
		imagecopyresized($thumb, $pic, 0, 0, 0, 0,
		$twidth, $theight, $width, $height);
	
		// Change page type to a jpeg
		header ("Content-type: image/jpeg");
	
		// Create jpeg image from thumbnail
		imagejpeg($thumb,"",75);
	
	} else {exit();}
the only problem is that when I execute it I get these two errors:

Warning: getimagesize() [function.getimagesize]: URL file-access is disabled in the server configuration in /home/public_html/path/thumbnail.php on line 7

Warning: getimagesize(http://www.mysite.com/images/image.jpg) [function.getimagesize]: failed to open stream: no suitable wrapper could be found in /home/public_html/path/thumbnail.php on line 7
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

PHP is configured to stop you accessing files via a URL. You can only access local files.
utinaeniduin
Forum Newbie
Posts: 4
Joined: Thu Aug 30, 2007 11:16 pm

Post by utinaeniduin »

ooh ok. lucky for me I was just using that as an example. the way I was planning on using it is by linking to a php image fetcher called getdata.php. so the url that I am trying to get to work is http://www.mysite.com/pathto/thumbnail. ... a.php?id=3

but now I am getting this error:

Warning: getimagesize(getdata.php?id=3) [function.getimagesize]: failed to open stream: No such file or directory in /home/public_html/path/thumbnail.php on line 7.

I am able to fetch the original image by going to http://www.mysite.com/pathto/getdata.php?id=3
utinaeniduin
Forum Newbie
Posts: 4
Joined: Thu Aug 30, 2007 11:16 pm

Post by utinaeniduin »

does anyone know why this is happening?
Last edited by utinaeniduin on Sat Sep 01, 2007 7:53 pm, edited 1 time in total.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Try using absolute paths.
utinaeniduin
Forum Newbie
Posts: 4
Joined: Thu Aug 30, 2007 11:16 pm

Post by utinaeniduin »

ok i figured it out that this script i have does not work when i use the getdata.php file (which fetches images from a db) as the url. this script did work when i tried using a picture in the same folder. does anyone have an idea of how i can get an image from a db resized without saving it as a new file?
Post Reply