[email protected] Posted December 17, 2008 Share Posted December 17, 2008 Hey there. Sorry to be asking this as my first post, but here goes, hope you manage to figure out what went on here. Basically I have a localhost website -- before I get a server I want a system properly running. Anyways, I have an image upload form which should resize an image and copy it to a further resized thumbnail. newphoto.template.php <?php print_r($_FILES); if (isset($_POST['photo'])) { $photo = image_resize($_FILES['photo']['tmp_name'], 800, 600); $thumb = image_resize($_FILES['photo']['tmp_name'], 160, 120); mysql_query("INSERT INTO `photos` (`poster_id`) VALUES ('".$_COOKIE['id']."')"); $result = mysql_query("SELECT `photo_id` FROM `photos` ORDER BY `photo_id` DESC LIMIT 1"); $photo_id = mysql_fetch_row($result); $size = getimagesize($_FILES['photo']['tmp_name']); switch ($size['mime']) { case 'image/jpeg': imagejpeg($photo, 'uploads/photos/photo_'.$photo_id[0].'.jpg'); imagejpeg($thumb, 'uploads/photos/thumbs/photo_'.$photo_id[0].'.jpg'); break; case 'image/png': imagepng($photo, 'uploads/photos/photo_'.$photo_id[0].'.png'); imagepng($thumb, 'uploads/photos/thumbs/photo_'.$photo_id[0].'.png'); break; } if (!$_POST['more']) { redirect('./?p=img&id='.$photo_id[0]); } } ?> <form action="?p=newphoto" method="post" enctype="multipart/form-data"> <input type="file" name="photo" /><br /> <input type="checkbox" checked="checked" name="more" />Upload another photo afterwards<br /> <input type="submit" value="Upload" /> </form> images.php <?php function image_resize($img_src, $new_w, $new_h) { $size = getimagesize($img_src); print_r($size); switch ($size['mime']) { case 'image/jpeg': $old = imgcreatefromjpeg($img_src); case 'image/png': $old = imgcreatefrompng($img_src); } $ratio = ($size[0] > $size[1]) ? $w / $new_w : $h / $new_h; echo $ratio; $w = $w / $ratio; $h = $h / $ratio; $img_dest = imagecreatetruecolor($w, $h); imagecopyresampled($img_dest, $old, 0, 0, 0, 0, $w, $h, $size[0], $size[1]); return $img_dest; } ?> Basically what happens, is, nothing. No file is uploaded, no SQL insertion is done (which leads me to believe the problem is in the image_resize function?). I'm rather new to image manipulating, this is the first method I tried creating using one. It's supposed to return a resized (keeping ratio), copied image of the source image provided. Maybe I didn't get the hang of GD functions right? A few notes... [*]Both files are included in other template files, which have DB access, and other functions. [*]Ignore the fact I didn't validate correct file type, sizes, and if $_COOKIE['id'] actually exists, I'll do that once I'm sure everything works. If you need any further information just say so, thanks in advance! Link to comment https://forums.phpfreaks.com/topic/137333-image-uploadresize-problems/ Share on other sites More sharing options...
[email protected] Posted December 17, 2008 Author Share Posted December 17, 2008 Ahhh *don't kill me* but I can't find the edit/modify button on the upper post. I forgot to mention, that no errors were generated. Link to comment https://forums.phpfreaks.com/topic/137333-image-uploadresize-problems/#findComment-717526 Share on other sites More sharing options...
[email protected] Posted December 17, 2008 Author Share Posted December 17, 2008 Bump? >= Link to comment https://forums.phpfreaks.com/topic/137333-image-uploadresize-problems/#findComment-717640 Share on other sites More sharing options...
[email protected] Posted December 17, 2008 Author Share Posted December 17, 2008 C'mon, I hate bumping, but I kinda need this =\ I've tried fixing it further but no luck. Link to comment https://forums.phpfreaks.com/topic/137333-image-uploadresize-problems/#findComment-718122 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.