JPEG Image Upload

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dubs
Forum Commoner
Posts: 28
Joined: Tue Oct 12, 2004 4:55 pm

JPEG Image Upload

Post by dubs »

Hi All

I've got an idea for a project that involves a user uploading a high res image to my server so we can artwork the files.

Could someone give me some advise on what is the best way to upload a large image max (5mb) . For example I would I stop the server from timing out during the upload and is there a way to create a thumbnail using the GD library etc

Cheers

Rich
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Well if the timeout time is set to something like 60 or 90, then you can set it to something higher for the duration of the scripts execution with [php_man]set_time_limit()[/php_man].

Other than that, it's just standard file uploading procedure.
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

My file upload class in the code snippets section should cover you for most things.
hurdy gurdy
Forum Commoner
Posts: 40
Joined: Mon Jun 09, 2003 8:19 pm

Re: JPEG Image Upload

Post by hurdy gurdy »

I believe the default value for PHP's upload max file size is 2 megs. You might have to change that, if you havent already.
dubs
Forum Commoner
Posts: 28
Joined: Tue Oct 12, 2004 4:55 pm

Post by dubs »

Cheers all 8O
User avatar
emperor
Forum Newbie
Posts: 16
Joined: Tue Mar 02, 2004 11:20 am
Location: UK

Post by emperor »

To create a thumbnail from the uploaded JPEG try this:

Code: Select all

<?php
    $src = ImageCreateFromJPEG ($src_filename);

    $width = ImageSx ($src);
    $height = ImageSy ($src);
    $x = $desired_width;
    $y = $desired_height;

    $dst = ImageCreateTrueColor ($x, $y);
    ImageCopyResampled ($dst, $src, 0, 0, 0, 0, $x, $y, $width, $height);
    ImageJPEG ($dst, $dst_filename);    // or ImagePNG or whatever
    DestroyImage ($dst);
?>
Post Reply