Jump to content

Image Resizing Help Needed


mastershake22

Recommended Posts

I am using an upload page for photos, and When I try to display the photo after it's been uploaded it only displays part of the photo. I realize that that is probably because the file is too big, but if anyone out there knows how to resize an image for display after its been uploaded I would really appreciate the help. This is the get.php page I'm using to display the image

<?php
$id=$_REQUEST['id'];
$image=mysql_query("SELECT*FROM demophotos WHERE id=$id");
$image=mysql_fetch_assoc($image);
$image=$image['image'];

header ("Content-type: image/jpeg");

echo $image;
?>

 

And this is the photo.php page that I'm using for uploading

 

<?php
$file= $_FILES['image'] ['tmp_name'];

if (!isset($file))

	echo "Please select an image";
else
{
$image= addslashes(file_get_contents($_FILES['image'] ['tmp_name']));
$image_name= addslashes($_FILES['image'] ['name']);
$image_size= getimagesize($_FILES['image'] ['tmp_name']);
if ($image_size==FALSE)
echo "Well that's not an image now, is it?";

else 
{

	if(!$insert= mysql_query("INSERT INTO demophotos(id, name, image) VALUES ('', '$image_name', '$image')"))	
		echo "?";

	else
	{
	$lastid=mysql_insert_id();
	echo "Image uploaded <p /> You're Image: <p /><img src= get.php?id=$lastid>";	
	}
}
}
?>       

Link to comment
https://forums.phpfreaks.com/topic/231566-image-resizing-help-needed/
Share on other sites

First, how come you are using $image multiple times to do different things? It just overwrites the previous $image's job. Also, in your second code, it seems you don't have brackets to end certain if statements, etc.

 

This may not solve your problem, but organizes the code and fix some missing brackets:

 

<?php
$file= $_FILES['image'] ['tmp_name'];

if (!isset($file))
{

	echo "Please select an image";
}
else
{
$image= addslashes(file_get_contents($_FILES['image'] ['tmp_name']));
$image_name= addslashes($_FILES['image'] ['name']);
$image_size= getimagesize($_FILES['image'] ['tmp_name']);
}
elseif ($image_size==FALSE)
{
echo "Well that's not an image now, is it?";
}
else 
{

	if(!$insert= mysql_query("INSERT INTO demophotos(id, name, image) VALUES ('', '$image_name', '$image')"))	
	{
		echo "?";
	}
	else
	{
	$lastid=mysql_insert_id();
	echo "Image uploaded <p /> You're Image: <p /><img src= get.php?id=$lastid>";	
	}
}
?>       

 

Edit:

 

Also, if I'm not mistaken, you shouldn't need to do

 

echo $image;

 

If your already setting a header for it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.