Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help converting a script.

Status
Not open for further replies.

Rixride

IS-IT--Management
May 3, 2001
41
US
I am new to Perl and would like to figure out how to change this import script to import PDF's instead of Images.

here i the script:


#!/usr/bin/perl
package Egrail;

###########################################################
##
## $Id: importassets.pl,v 1.5 2002/07/11 09:24:11 achoi Exp $
##
##
## Author: unknown
##
## Created: unknown
##
## Description: Bulk image upload
##
## Outputs: none
##
## Returns: none
##
## Side-effects: insertion of assets
##
## Status: none
##
## Comments:
## usage: importassets.pl [-d] [-ddb]
## [-parent parent_folder] [-ext relativeroot] ## site importdir
##
## -d : debug mode
## -ddb : database debug mode
## -parent parent_folder : insert assets under a specific parent folder
## -ext relativeroot : create assets as external assets url
## site : site name
## importdir : directory where are stored the assets
##
## Teamtrack Id: BUG02006
##
###########################################################

$parent_folder = '';
$external = '';
$check = shift;
while ($check =~ /^-/) {
if ($check =~ /usehtml/) {
$usehtml = 1;
} elsif ($check =~/d$/) {
$Debug = 1;
} elsif ($check =~/ddb$/) {
$DBDebug = 1;
} elsif ($check =~/parent$/) {
$parent_folder = shift;
} elsif ($check =~/ext$/) {
$external = shift;
}
$check = shift;
}
$phpdir = $check;
$import_dir = shift;
die "Usage: $0 [-usehtml] [-d] [-ddb] [-parent parent_folder] [-ext relativeroot] site importdir\n" unless ($phpdir && $import_dir);

$EGRAIL_CONFIG = "/usr/local/eGrail/config";
$EGRAIL_CONFIG = $ENV{"EGRAIL_CONFIG"} if ($ENV{"EGRAIL_CONFIG"});

if (-r "$EGRAIL_CONFIG/config.pl") {
require "$EGRAIL_CONFIG/config.pl";
} else {
$HOME = $ENV{"HOME"};
$EGRAIL_CONFIG = "$HOME/eGrail";
if (-r "$EGRAIL_CONFIG/config.pl") {
require "$EGRAIL_CONFIG/config.pl";
} else {
die "Unable to load configuration file, config.pl";
}
}

# Load in the defaults
require "$ScriptRoot/$ScriptDir/perl-lib/common.pl";
require "$ScriptRoot/$ScriptDir/perl-lib/systemcall.pl";

# FUNCTION Defaults
$image_import = 1;
$image_external = 1; # Import them externally
$image_folderroot = 2;
$import_imagesonly = 1;

$OutputErrors = 1;

$pcid = 0;
if ($parent_folder) {
$pcid = &Egrail::Assets::GetFolder($parent_folder);
}

# Run the Thing;
find(\&ImportAssets, $import_dir);

exit; # go away peacefully

# Only functions below this line

sub ImportAssets {

my($name, $dir, $file) = ($File::Find::name, $File::Find::dir, $_);
my($mydir) = substr $dir, length($import_dir); # This gives us the relative root /image/etc
my($am_content) = '';

# We don't want CVS files
$File::Find::prune = 1 if ($_ =~ /^CVS$/);
return if ($_ =~ /^CVS$/);

# No directories this far
return if (-d "$dir/$file");

if (($file =~ /gif$/i) || ($file =~ /jpeg$/i) || ($file =~ /png$/i) || ($file =~ /jpg$/i)) { # Image

print "Examining $name, $dir, $file ... ";

if ($external) { $ext_url = "$external$mydir/$file"; } else { $ext_url = ""; }
if ($pcid) {
$aid = &Egrail::Assets::SubmitAsset($file, $file, $file, "$parent_folder/$mydir", $ext_url);
if ($Egrail::Debug) { print "\nIMPORTED: ($aid) $mydir/$file -> $parent_folder as $file\n"; }
} else {
$aid = &Egrail::Assets::SubmitAsset($file, $file, "$dir/$file", $mydir, $ext_url);
if ($Egrail::Debug) { print "\nIMPORTED: ($aid) $mydir/$file -> $mydir as $file\n"; }
}
}
print "OK.\n";
return;

}


Thanks for any help you can offer.

-=Rick Cruz=-
 
This line :

if (($file =~ /gif$/i) || ($file =~ /jpeg$/i) || ($file =~ /png$/i) || ($file =~ /jpg$/i)) { # Image

Controls the file extensions that get imported

Make it

if( $file =~ /pdf$/i ) { # PDF

and it will only import files with the .pdf extension.
 
More info in the FAQ section here as well, just change the mime types

--Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top