Re: picture upload

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

 



William Stokes wrote:
> Hello,
> I'm building a web site for a sports team. I wan't them to be able to
> update
> their own site so I need to build a file upload system for their pictures.
> Pictures also need to resized to fit their spot in the web page. Any ideas
> or quidelines how to do this. I've never done this kind of stuff before.
> Thanks IA

For the file upload part, the PHP Manual has a section (before all the
functions) about how to do that.  Read it.  Try it.  Post if you get
stuck. :-)  Don't forget the ENCTYPE part!!!

For scaling the image, there are several options.

One is to force the user to only submit images that fit within a certain
size/parameters.  This is probably good to avoid people uploading HUUUUUGE
image files.

You also should add some code in your file upload to be *SURE* it *is* a
valid image, so your server does not become a clearing-house for the
latest cracked version of Doom or whatever is popular this week.  This
function will be especially useful:
http://php.net/getimagesize

Once you have the file uploaded, you could scale it right away, once, and
save the scaled version for use from then on.

Or, you could scale the image each time, on the fly.

The first option is more efficient.  The second is more flexible if you
want to change the image size later, or if you want to have thumbnails in
one page, and full-size in another.  (You can write one script to handle
both)

Your two main choices for scaling an image are:
GD, which has to be installed with PHP (use http://php.net/phpinfo to check)
ImageMagick (aka 'convert') which is a shell command you can install and
use http://php.net/exec to execute.

There are examples of using GD to scale images, and of using ImageMagick
(aka convert) to scale images with exec all over the 'net, so I won't try
and repeat them here.

Oh yeah:  Sooner or later, somebody will upload an image that's too SMALL.
 Don't try to scale it "up" -- That will be butt ugly.  Just display it
centered in the spot where the image belongs.  Test this with a tiny image
for yourself.

Security Note:  The directory where your uploaded images are stored should
*NOT* be in your htdocs web tree.  You can use PHP to make sure the image
is kosher and *move* it after you check to the web tree.  Or you can use
PHP to check/read/display the image, so it's never in your web-tree.

-- 
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