Gossamer Forum
Home : Products : DBMan : Customization :

New File Upload Mod

 
New File Upload Mod
Hi

I have just installed the new fileupload mod and I found that for record with ID 1 I was getting the images for 11, 12, 13 etc... This seems to fix it, where you want the image to print change this:

Code:
$file_test = $rec{$db_key} . ".";
foreach $file (@files) {
if ($file =~ /^$file_test/) {
to this:
Code:
$file_test = $rec{$db_key};
foreach $file (@files) {
if ($file =~ /^$file_test\./) {
Also if you want height and width's to be worked out the Image::Size Perl module from http://www.cpan.org/ is easy to use:

Add this to the top of the html.pl file:

Code:
use Image::Size;
And where you want the image to be printed:
Code:
my ($x, $y) = imgsize ("$SAVE_DIRECTORY/$file");
print qq|<p><img src="$SAVE_DIRECTORY_URL/$file" alt="$rec{'Title'}" width="$x" height="$y" /></p>\n|;
Chris


--
http://webarchitects.co.uk/
 
Re: New File Upload Mod In reply to
Thanks, Chris. I changed every instance of the use of $filetest. I figured it wouldn't hurt. Smile

I think I'm going to have to take your word for the use of the Image module. My server doesn't have it and I haven't had any luck installing any modules in my own webspace.


JPD
 
Re: New File Upload Mod In reply to
Hi JPD

Installing perl modules is actually quite easy if you have shell access, this is what I do:

first make a directory for the source code and perl modules: (~ is the same as /home/chris)
Code:
mkdir ~/src
mkdir ~/perl
then get the perl module and extract it:
Code:
cd ~/src
lynx http://search.cpan.org/search?dist=Image-Size
(use the down arrow till you gett he link to the file then hit 'd' for download and then 'q' to quit lynx)
tar -zxvf Image-Size-2.903.tar.gz
Then compile and install it:
Code:
cd Image-Size-2.903
perl Makefile.PL PREFIX=~/perl
make
make test
make install
Then use something like this in the Perl script:

Code:
require "/home/chris/perl/lib/site_perl/5.005/Image/Size.pm";
Chris

--
http://webarchitects.co.uk/
 
Re: New File Upload Mod In reply to
Thanks. I'll give it a try.

I didn't have much luck trying to install another module, following very similar instructions. But I'm always willing to give it one more shot. Smile

JPD
 
Re: New File Upload Mod In reply to
I got it installed! Thank you!!!! Laugh

I was wondering if the file -- Size.pm -- could just be used, rather like Links includes Template.pm. (I'm thinking in terms of adding this to a mod and it would be much easier for folks if they could just download a file.)

Do you know?

JPD
 
Re: New File Upload Mod In reply to
Well, it is installed, but I'm not getting it to work.

I have the "require" line in db.cgi, with all the other "requires." I tried it with both the location set by the installation and within the dbman directory.

I used

($x,$y) = imgsize("$SAVE_DIRECTORY/$file");
print qq|<img src= "$SAVE_DIRECTORY_URL/$file" HEIGHT="$x" WIDTH="$y">|;

to print out the dimensions, but I got

fatal error: Undefined subroutine &main::imgsize called at ./html.pl line 132.

I tried adding Image::Size to db.cgi, but then I got a 500 error.

I'm pretty certain that Size.pm is being loaded. I temporarily added an extra error message to show if it didn't (I never got it) and then I altered the path to be wrong. I got an error then.

Something I'm missing?

JPD
 
Re: New File Upload Mod In reply to
Hi JPD

Cool you got the module installed -- you should be able to install any Perl modules you want now :-)

However that require line must be totally wrong, my fault :-(

This should work, add a sym link from the directory with db.cgi in it to the Size.pm file:

ln -s ../perl/lib/site_perl/5.005/Image/Size.pm

then use this at the top of html.pl:

use Size;

The file Size.pm can be included in your mod, as can any module on CPAN as long as your code is released under the GPL or the Perl license, as far as I know. Though the DBMan license might conflict with the GPL?

Chris



--
http://webarchitects.co.uk/
 
Re: New File Upload Mod In reply to
In Reply To:
add a sym link from the directory with db.cgi in it to the Size.pm file:

ln -s ../perl/lib/site_perl/5.005/Image/Size.pm
Ummmm. What's a sym link? Smile I know it stands for "symbolic link" (or at least I think it does), but what would I do with the line you have above? Does this go into db.cgi? Is it something I do in a telnet session?

JPD
 
Re: New File Upload Mod In reply to
Hi

Yeah a symbolic link -- you need to do it in a telnet / SSH session. It'll mean that the Size.pm file appears to be in the same directory as db.cgi.

The advantage of doing it this way is that when you update Perl modules you don't need to move them... however it might just be easier to move the Size.pm file into the same directory...

I hope you get it working.

Chris

--
http://webarchitects.co.uk/
 
Re: New File Upload Mod In reply to
Oh. I see.

I did move it to the db.cgi directory. It isn't being recognized or something.

Okay. Here's what I have.

In db.cgi, I have

Code:
eval {
unshift (@INC, $db_script_path);
require 5.003;
unless ($db_setup =~ /^[A-Za-z0-9]+$/) { die "Invalid config file name: $db_setup"; }
require "$db_setup.cfg"; # Database Definition File
require "auth.pl";
require "Size.pm";
use Size;

};
I didn't know if I needed the use Size; line, but it doesn't give me any errors. I tried using Image::Size and I got a 500 error.

In sub html_record, I have

Code:
($x,$y) = imgsize($file);
print qq|<tr><td colspan=2><img src= "$SAVE_DIRECTORY_URL/$file" HEIGHT="$x" WIDTH="$y"></td></tr>|;
When I add the above in, I get

fatal error: Undefined subroutine &main::imgsize called at ./html.pl line 132.

I even tried copying Size.pm and pasting it into db.cgi. I didn't get an error message, but I didn't get the dimensions returned either.

I checked all of the "use" functions in Size.pm and they are installed on my server.

I'm at a loss. I really hate giving up on anything, but this may be something I'm going to have to just accept that I can't use.

JPD
 
Re: New File Upload Mod In reply to
Hi people!

Ive been following this at a distance, as this will fit in with the thumbnail mod.

Carol, the error you got sounds very familiar. I got it when using thumbnail, but can't remember why!

One thing I noticed:

Should:
($x,$y) = imgsize($file);

be

($x,$y) = imgsize("$SAVE_DIRECTORY_URL/$file");

I'm pretty sure my error may have been when I was not specifying the directory for the thumbnails.


Also you should not need to use the

require Image::Size

as in Size.pm you have: package Image::Size;

But of course you will need require size.pm.

Have you tried using
($x,$y) = &imgsize("$SAVE_DIRECTORY_URL/$file");


I'm totally guessing here, this is just what I picked up from using thumbnail.cgi!!!

Hope something helps!!!

Cheers!
Ben
------------
http://www.travel-experiences.com
 
Re: New File Upload Mod In reply to
I appreciate the input, Ben. I did what you said, but I got the same results. (You are right about the $SAVE_DIRECTORY variable, though. If I ever get this to work, it'll be necessary.) But with or without the &, I still get the same "Undefined subroutine" message.


JPD
 
Re: New File Upload Mod In reply to
worth a try!

All I can think of doing is creating a seperate file to test if the actual size.pm is working???

But Chris got it working!!!! Tongue

Just one quick Idea. You can use:

$size = html_imgsize("globe.gif");
and in your image tags just use $size (as it equals: 'width="xx" height="yy"' )

This sub routine is about 100 lines shorter, so if there is a prob with that, this might work better?

Let me know if anything works, I would love to use this!

Cheers!
Ben
------------
http://www.travel-experiences.com
 
Re: New File Upload Mod In reply to
Hi JPD

Try this:

use Size.pm;

and delete the require line?

Chris

--
http://webarchitects.co.uk/
 
Re: New File Upload Mod In reply to
Hi Ben

You suggest:
Code:
($x,$y) = imgsize($file);

be

($x,$y) = imgsize("$SAVE_DIRECTORY_URL/$file");
but this should be:
Code:
($x,$y) = imgsize("$SAVE_DIRECTORY/$file");
--it's a path not a URL

Chris


--
http://webarchitects.co.uk/
 
Re: New File Upload Mod In reply to
"use Size;" doesn't do it either. I have used every possible permutation of this that I can think of and nothing seems to work. Maybe it's my server.

(I hadn't noticed the $SAVE_DIRECTORY_URL in what Ben wrote. I added the right variable to my file.)

Chris, did your server already have the module installed?

JPD
 
Re: New File Upload Mod In reply to
Hi

Where I have used this I have actually either had root access or had the sys-admin install it... however I _know_ it can be done without root access... I'm not sure what the problem is but I suspect it's something really simple to fix...

Chris

--
http://webarchitects.co.uk/
 
Re: New File Upload Mod In reply to
It probably is. I've started getting different error messages, which I'll go into later. I've been up all night and I gotta get some sleep!! Smile


JPD
 
New File Upload Mod getting jpg and gif image size In reply to
Hi

This is what you need to do to to get Image::Size working on *nix, stuff with #'s are comments:

cd # get to home dir
mkdir src # make a dir for the source code
cd src
lynx http://search.cpan.org/search?dist=Image-Size # down arrow to tar ball and then hit d for download
tar -zxvf Image-Size-2.903.tar.gz
cd Image-Size-2.903
perl Makefile.PL PREFIX=~/
make
make test
make install
cd ../cgi-bin/db/ # go to directory with DBMan in it
ln -s ../../lib/perl5/site_perl/5.005/Image/ # make a sym link to the Image directory
ln -s ../../lib/perl5/site_perl/5.005/auto/ # make a sym link to the auto directory

The add this to the top of html.pl

use Image::Size;

Then amend the new file upload mod to something like this:

my ($x, $y) = imgsize ("$SAVE_DIRECTORY/$file");
print qq|<p><img src="$SAVE_DIRECTORY_URL/$file" alt="$rec{'Title'}" width="$x" height="$y" /></p>\n|;

JPD - all you need to do is add the sym link -- sorry I didn't get this sorted sooner but I have only just installed it on a server without root...

Chris


--
http://webarchitects.co.uk/
 
Re: New File Upload Mod getting jpg and gif image size In reply to
Ah-ha!

Yes, the last error messages I got referred to auto/ something or other. (As I said in the other post, I got frustrated and decided to put it away for a bit.)

Thank you! I will give it a shot as soon as I can.


JPD
http://www.jpdeni.com/dbman/
 
Re: New File Upload Mod In reply to
If you grab the CPAN module then installing packages is really easy, all you need to do after that is invoke - perl -MCPAN -e shell; - and you get a nice interactive shell for installing modules, which also allows you to search for them!

tom

 
Re: New File Upload Mod getting jpg and gif image size In reply to
Ha---llelujah! Ha---llelujah! Hallelujah! Hallelujah! Halle--lujah!

I finally got it!!!!!! Oh happy day!!!!!!!!

I reinstalled the whole thing, following your instructions and set up the sym links. I did have to alter them a bit, to put the full path to the Image and auto directories. And the paths were a little different when I installed them. So my commands for the sym links were

ln -s /path/to/perl/lib/site_perl/5.005/Image/
ln -s /path/to/perl/lib/site_perl/5.005/auto/

If you want to check it out, go to http://www.jpdeni.com/...w_records=1&ID=*. Check the source code for the page and you'll see

<img src="http://www.jpdeni.com/uploads/73.jpg" alt="test" width="245" height="506">

and

<img src="http://www.jpdeni.com/uploads/75.gif" alt="Gif test" width="111" height="140">

Oh, happy day!!!!!! Laugh



JPD
http://www.jpdeni.com/dbman/
 
Re: New File Upload Mod getting jpg and gif image size In reply to
Well done Carol!!!

I'm going to have a bash at this now. Hopefully it'll go OK. As I have the autothumbnails working this should make the whole photo album rock!!!

SmileSmileSmile !!!

Cheers!
Ben
------------
http://www.travel-experiences.com
Post deleted by Albino_Smurf In reply to
 
Re: [benseb] New File Upload Mod getting jpg and gif image size In reply to
I think the final solution was having use Image::Size; rather than size.pm?

You may want to post what you are trying to do along with the link to your code in the Perl/cgi forum where the programmers hang out. They may be familiar with using the module in question.



Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/