Gossamer Forum
Home : Products : DBMan : Customization :

Another "file upload mod" question!

Quote Reply
Another "file upload mod" question!
Hi,

I have inserted the single file upload mod for uploading a graphic file. Works very good indeed.

But can I limit the image dimensions some way to prevent for example uploading of images bigger than 400 pixels in width?

Regards,

Akula
Quote Reply
Re: [akula] Another "file upload mod" question! In reply to
You would need to have the ImageMagick module installed on your server in order to be able to read the width of the file. I don't have it available, so I can't test it out.

There is a lot of information on the module on the 'net, if you have it available to use.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Another "file upload mod" question! In reply to
I even dont know it is available on my server or not. I guess I have to search and learn about this module...

thanks,

Akula
Quote Reply
Re: [akula] Another "file upload mod" question! In reply to
I know it's been a while since you posted this, but I came across an answer for you.

First, go to http://webnet77.com/scripts/list-modules/ and download the free script there. (The download link is at the bottom of the page.) Unzip the file. Upload list-modules.pl to your cgi-bin (or wherever you put executable perl scripts). Be sure you upload in ASCII mode. CHMOD the file to 755. Then run it. You'll get a list of all of the modules that are installed on your server, in three columns, listed alphabetically. The one you want to look for is Image::Size.

If you have that module you're all set. If not, let me know what, if any, Image modules there are and I'll see if I can work with them. For the rest of this, I'm going to assume that you have Image::Size available to you.

In db.cgi, after

$db_script_path = ".";

add

Code:
use Image::Size


(If you don't have the Image::Size module on your server, it's likely that your script will crash just by having that line in there.)

In your .cfg file, where you have your other file upload parameters, add

Code:
$max_width = 400;
$max_height = 200;



Use whatever numbers you want. Don't make the numbers 0, though. If you don't want to put a limit on either the height or the width, make it some huge number like 5000. You also might want to put a notation in sub html_record_form about the maximum size that is acceptable so your users don't get a nasty surprise.

Back in db.cgi, sub validate_upload, towards the end, after

chmod (0666, "$SAVE_DIRECTORY\/$filename");

Code:
($img_height,$img_width) = imgsize("$SAVE_DIRECTORY\/$filename");
if (($img_height>$max_height) or ($img_width>$max_width)) {
unlink "$SAVE_DIRECTORY\/$filename";
return "Your image is too large. Your image is
$img_height tall and $img_width wide. We can only
accept files that are $max_height tall and
$max_width wide. Your image was not saved."
}



If you want to use the size in the image tag when you print it out the image, make the following change in html.pl, sub html_record:

Code:
$size = html_imagesize("$SAVE_DIRECTORY\/$filename");
print qq|<img src= "$SAVE_DIRECTORY_URL/$file $size">|;


I haven't tested it out yet. I wanted to give you the info first. I'm going to go give it a try and see what errors I've made. :-)


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.