Re: Uploading pic

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux