mastershake22 Posted March 24, 2011 Share Posted March 24, 2011 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 More sharing options...
3raser Posted March 24, 2011 Share Posted March 24, 2011 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. Link to comment https://forums.phpfreaks.com/topic/231566-image-resizing-help-needed/#findComment-1191610 Share on other sites More sharing options...
mastershake22 Posted March 24, 2011 Author Share Posted March 24, 2011 I use the $image multiple times because php reads linearly (sp?) and every new $image builds off the previous one to combine all the functions into one variable. Link to comment https://forums.phpfreaks.com/topic/231566-image-resizing-help-needed/#findComment-1191612 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.