Re: Uploading pic

From: Date: Sat, 29 Apr 2006 09:25:16 +0000
Subject: Re: Uploading pic
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-235086@lists.php.net to get a copy of this message
On Thu, April 27, 2006 8:15 am, Rosen wrote: > I have this problem with uploading images: > I try several PHP classes for upload of files on server ( pictures in > my > case ), but if some user only renames some file as ".jpg" the script > uploads the file even the file format is not .jpg - i.e. - file > "test.mpg" - the user renames it to "test.jpg" - and the script upload > it on server. Of course after this the website don't show any pi - it > shows like pic does not exists. http://php.net/getimagesize can be used on the files uploaded to make sure that they at least LOOK like they are valid images. A clever user COULD manage to upload a file whose first X bytes "looked" like a JPEG, but it was really an .mpg after those X bytes -- but it's really unlikely that the file would "work" as an .mpg correctly... Most likely, it would just be a corrupt file, neight .jpg nor .mpg > I need also to control the dimension of pictures ( in pixels), size > in > kb and type of files ( .gif, .jpg ). > > Is there a way to do this with some script ? http://php.net/imagecopyresampled will take care of X and Y You'd have to output the file with http://php.net/imagejpg and/or http://php.net/imagegif and then use http://php.net/filesize to determine how big the file was -- or keep it all in RAM using http://php.net/ob_start http://php.net/ob_get_contents and http://php.net/ob_end_clean and then use http://php.net/strlen You may find that the hassle of worrying about the actual Kb is too much effort, when you can pretty well predict that a 400x300 JPEG will be "not TOO big" (or whatever numbers work for you) -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#235086) next »