#!/usr/bin/perl #use lib qw(/home/catmindeye/free4med.com/cgi-bin/lib/); ######################################################### # class06-upload.pl - Create a form that can upload images ######################################################### if ($0=~m#^(.*)\\#){ $execDir = "$1"; } # Win/DOS elsif ($0=~m#^(.*)/# ){ $execDir = "$1"; } # Unix else {`pwd` =~ /(.*)/; $execDir = "$1"; } # Unix # Get DB Login Info require "$execDir/info.pl"; # Use CGI Perl module to output any error msgs to browser use CGI::Carp qw(fatalsToBrowser); # Define the name of the script just for reference $scriptName = "sendhttp.pl"; $pageTitle = "Welcome to the Forum"; # Obtain any variables submitted either in the URL string # or by an HTML form via the GET or POST method, and # place in the %INPUT_VARS hash array %INPUT_VARS = {}; &input_vars_receive; &input_vars_parse; ######################################################### # Define our DB info ######################################################### use DBI(); $dbpath ="dbi:mysql:database=mobile;host=mysql.free4md.com"; ######################################################### # Connect to the database. ######################################################### # This only needs to be done once per script $dbh = DBI->connect($dbpath, "fff", "ffff", {'RaiseError' => 1, 'PrintError' => 1}); # Define where flash movies are on the server $flash_file = "http://www.free4md.com/"; #$media_filename = $INPUT_VARS{$media_filename}; $media_filename = "pieceofshit.flv"; ######################################################### # Get the name of the video and send it to flash ######################################################### $video .= "$flash_file.$media_filename"; # We need to URL encode the data for HTTP transport $video = &url_encode($video); # This subroutine is at the end of this script # We are now going to send one variable to Flash. The name # of the var in Flash will be "videoData" and it will contain # the contents of the Perl var $video, which is the listing # of what is in the instrument table in my DB print qq^videoData=$video^; # We have now sent this data to Flash #print "Location: flashforumtesttwo.pl?forum_id=69\n\n"; ######################################################### # Disconnect from the database. ######################################################### # Always the last thing you do before exiting your script $dbh->disconnect(); exit(0); ######################################################### # Takes data from an HTML Form or URL string ######################################################### sub input_vars_receive { $formData = $ENV{'QUERY_STRING'}; if ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $formData, $ENV{'CONTENT_LENGTH'}); } } ######################################################### # Parses form info ######################################################### sub input_vars_parse { local($name,$value,$pair); local(@pairs) = split(/&/, $formData); # Get parameter names, their values and copy into $INPUT_VARS array foreach $pair (@pairs) { ($name,$value)=split(/=/,$pair); $value=~tr/+/ /s; $value=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; $INPUT_VARS{$name}=$value; } } ######################################################### # Write To Log File ######################################################### sub write_to_log ######################################################### { # Write to log file local($msg) = @_; open INPTR, ">>$logFile"; print INPTR "$msg\n"; close INPTR; } ######################################################### # Trim whitespace ######################################################### sub trim_it { local($msg) = @_; while ($msg=~/^\s/i) { $msg=~s/^\s//i;} while ($msg =~/\s$/) { $msg =~s/\s$//; } return $msg; } ######################################################### # Escape single quotes for DB entry ######################################################### sub escape_quotes { local($msg) = @_; local($delim) = "'"; local($rep) = "''"; $msg =~s/$delim/$rep/eg; return $msg; } ######################################################### # URL-encode data ######################################################### sub url_encode { my($toencode) = @_; $toencode=~s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg; return $toencode; }