graham23s Posted March 17, 2008 Share Posted March 17, 2008 Hi Guys, i was wondering if you guys could tel me what you guys do in regards to a couple of things. 1) when a user uploads an image what size should the MAXIMUM be i have it set at 3mb at the minute. 2) what dimensions to allow photos to be before they can be uploaded i.e 1000x800 etc, right now i have no limitations. cheers for any advice guys Graham Quote Link to comment Share on other sites More sharing options...
craygo Posted March 17, 2008 Share Posted March 17, 2008 The size of the picture would depend on what you have uploads set for in the php.ini file. As a recommendation you may want to consider what a good size(dimension) image and the approximate size(KB). I have images on my site which are around 1024X800 or so and they are around 2mb or less in size. I think you are better off with keeping a size limitation rather than a dimension limitation. That way the picture can keep it's original orientation. Ray Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted March 17, 2008 Share Posted March 17, 2008 the answer to both questions is: it depends on your needs and your configuration. Do you need to permit larger files or smaller files? will the images be displayed? if so, at what size? there are no general rules; it depends on what you're doing with the images. Quote Link to comment Share on other sites More sharing options...
graham23s Posted March 17, 2008 Author Share Posted March 17, 2008 Hi Guys, Thnaks for the tips, it's basically a kind of networking site, i am trying to stick to a certain guideline for future projects, my fear is they upload large images and when you view they're profile for example it throws the site layout out of whack kind of thing. Graham Quote Link to comment Share on other sites More sharing options...
bobinindia Posted March 17, 2008 Share Posted March 17, 2008 You will want to make sure you contol the sizes of the images The code below converts the images into three different sizes as defined by the DEFINE. Use them as you need. Modify the code as per your own database etc. Hope it is useful define ("MAX_SIZE", "5000"); define ("WIDTH", "75"); define ("HEIGHT", "50"); define ("BWIDTH", "150"); define ("BHEIGHT", "100"); define ("FWIDTH", "600"); define ("FHEIGHT", "400"); function make_thumb($img_name,$filename,$new_w,$new_h) { $ext = getExtension($img_name); if(!strcmp("jpg", $ext) || !strcmp("jpeg",$ext)) $src_img=imagecreatefromjpeg($img_name); if(!strcmp("png",$ext)) $src_img=imagecreatefrompng($img_name); $old_x=imageSX($src_img); $old_y=imageSY($src_img); $ratio1=$old_x/$new_w; $ratio2=$old_y/$new_h; if($ratio1 > $ratio2) { $thumb_w=$new_w; $thumb_h=$old_y/$ratio1; } else { $thumb_h=$new_h; $thumb_w=$old_x/$ratio2; } $dst_img=imageCreateTrueColor($thumb_w,$thumb_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); if(!strcmp("png",$ext)) imagepng($dst_img,$filename); else imagejpeg($dst_img,$filename); imagedestroy($dst_img); imagedestroy($src_img); } //end function make_thumb function getExtension($str) { $i = strrpos($str, "."); if (!$i) { return "";} $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } //end getExtension func $errors=0; if(isset($_POST['Submit'])) { while(list($key,$value) = each($_FILES[images][name])) { if(!empty($value)){ // this will check if any blank field is entered $filename = $value; { $filename = stripslashes($_FILES[images][name]); $extension = getExtension($value); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) { echo '<h2>Invalid extension</h2>'; $errors=1; } else { $size=getimagesize($_FILES['images']['tmp_name']); $sizekb=filesize($_FILES['images']['tmp_name']); if ($sizekb > MAX_SIZE*1024) { echo '<h2>Over the file size limit<h2/>'; $errors=1; } $image_name=microtime(1).'.'.$extension; $newname="images/".$image_name; $newbname="images/".$image_name; $newfname="images/".$image_name; $copied = copy($_FILES[images][tmp_name][$key], $newname); if (!$copied) { echo '<h2>Not copied</h2>'; $errors=1; } else{ $thumb_name='thumbs/thumb_'.$image_name; $thumb=make_thumb($newname,$thumb_name,WIDTH,HEIGHT); $bthumb_name='thumbs/bthumb_'.$image_name; $bthumb=make_thumb($newbname, $bthumb_name,BWIDTH,BHEIGHT); $fthumb_name='thumbs/fthumb_'.$image_name; $fthumb=make_thumb($newfname, $fthumb_name,FWIDTH,FHEIGHT); if($password == $pcheckrow['Pass']){ $insertimagepath = mysql_query("INSERT INTO imageid (id, imagepath, thumbpath, thumbpathB, thumbpathF, userid) VALUES ('','$newname', '$thumb_name', '$bthumb_name', '$fthumb_name','$userid');"); } else { echo "Sorry incorrect password"; } }} }}}} I haven't weeded out what you don't need. Good Luck Quote Link to comment Share on other sites More sharing options...
graham23s Posted March 17, 2008 Author Share Posted March 17, 2008 Hi Bob, thanks for that mate that is useful to me. thanks again Graham Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.