modify script

Reply

Join Date: Jun 2005
Posts: 6
Reputation: clarkkent is an unknown quantity at this point 
Solved Threads: 0
clarkkent clarkkent is offline Offline
Newbie Poster

modify script

 
0
  #1
Jun 19th, 2005
Hey guys. I have a prewritten script for uploading images to my server. It already checks filesize which i need. But i also need to check the image width and height to make sure it does not go over a certain size. I am not sure how to accomplish this as i am not very good with CGI. Would any of you mind helping me to accomplish this? Here is the script i have.

  1. #!/usr/bin/perl --
  2.  
  3. # Installation Instructions
  4. # http://www.perlscriptsjavascripts.com/perl/upload_lite/users_guide.html
  5.  
  6. # To order a custom install, please visit our "Secure order" page
  7. # and enter the standard installation fee in the "Custom Quote" field
  8.  
  9. ####################################################################
  10. #
  11. # Upload Lite.
  12. # ©2002, PerlscriptsJavaScripts.com
  13. #
  14. # Requirements: Perl5 WINDOWS NT or UNIX
  15. # Created: Febuary , 2001
  16. # Author: John Krinelos
  17. # Version: 4.0
  18. #
  19. # Based on Upload Gold, first release : September 2001
  20. #
  21. # This script is free, as long as this header and any copyright messages
  22. # remains in tact. To remove copyright messages from public web pages you
  23. # must purchase copyright removal.
  24. # http://www.perlscriptsjavascripts.com/copyright_fees.html
  25. #
  26. # Agent for copyright :
  27. # Gene Volovich
  28. # Law Partners,
  29. # 140 Queen St.
  30. # Melbourne
  31. # Ph. +61 3 9602 2266
  32. # gvolovich@lawpartners.com.au
  33. # http://www.lawpartners.com.au/
  34. #
  35. ####################################################################
  36.  
  37. # START USER EDITS
  38.  
  39. # absolute path to folder files will be uploaded to.
  40. # WINDOWS users, your path would like something like : images\\uploads
  41. # UNIX users, your path would like something like : /home/www/images/uploads
  42. # do not end the path with any slashes and if you're on a UNIX serv, make sure
  43. # you CHMOD each folder in the path to 777
  44.  
  45. $dir = "/home/oopsweb2/public_html/avatars";
  46. #$dir = "d:\\html\\users\\html\\images";
  47.  
  48. # absolute URL to folder files will be uploaded to
  49. $folder = "http://www.oopsweb.net/avatars/";
  50.  
  51. # maximum file size allowed (kilo bytes)
  52. $max = 8;
  53.  
  54. # for security reasons, enter your domain name.
  55. # this is so uploads may only occur from your domain
  56. # enter any part of your domain name, or leave this
  57. # blank if you don't mind other web sites using your copy
  58. $domain = "oopsweb.net";
  59.  
  60. # if a file is successfully uploaded, enter a URL to redirect to.
  61. # leave this blank to have the default message printed. If using
  62. # this var, it must begin with http
  63. $redirect = "http://www.oopsweb.net/avatars/success.htm";
  64.  
  65. # if you would like to be notified of uploads, enter your email address
  66. # between the SINGLE quotes. leave this blank if you would not like to be notified
  67. $notify = '';
  68.  
  69. # UNIX users, if you entered a value for $notify, you must also enter your
  70. # server's sendmail path. It usually looks something like : /usr/sbin/sendmail
  71. $send_mail_path = "/usr/sbin/sendmail";
  72.  
  73. # WINDOWS users, if you entered a value for $notify, you must also enter your
  74. # server's SMTP path. It usually looks something like : mail.servername.com
  75. $smtp_path = "mail.yourserver.com";
  76.  
  77. # set to 1 if you would like all files in the directory printed to the web page
  78. # after a successful upload (only printed if redirect is off). Set to 0 if you
  79. # do not want filenames printed to web page
  80. $print_contents = 1;
  81.  
  82. # allow overwrites? 1 = yes, 0 = no (0 will rename file with a number on the end, the
  83. # highest number is the latest file)
  84. $overwrite = 0;
  85.  
  86. # file types allowed, enter each type on a new line
  87. # Enter the word "ALL" in uppercase, to accept all file types.
  88. @types = qw~
  89.  
  90.  
  91. gif
  92.  
  93. ~;
  94.  
  95. ####################################################################
  96. # END USER EDITS
  97. ####################################################################
  98.  
  99. $folder =~ s/(\/|\\)$//ig;
  100.  
  101. $OS = $^O; # operating system name
  102. if($OS =~ /darwin/i) { $isUNIX = 1; }
  103. elsif($OS =~ /win/i) { $isWIN = 1; }
  104. else {$isUNIX = 1;}
  105.  
  106. if($isWIN){ $S{S} = "\\\\"; }
  107. else { $S{S} = "/";} # seperator used in paths
  108.  
  109. $ScriptURL = "http://$ENV{'SERVER_NAME'}$ENV{'SCRIPT_NAME'}";
  110.  
  111. unless (-d "$dir"){
  112. mkdir ("$dir", 0777); # unless the dir exists, make it ( and chmod it on UNIX )
  113. chmod(0777, "$dir");
  114. }
  115.  
  116. unless (-d "$dir"){
  117. # if there still is no dir, the path entered by the user is wrong and the upload will fail
  118. &PrintHead; #print the header
  119.  
  120. # get the Win root
  121. $ENV{PATH_INFO} =~ s/\//$S{S}/gi;
  122. $ENV{PATH_TRANSLATED} =~ s/$ENV{PATH_INFO}//i;
  123.  
  124. print qq~
  125. <table width="600">
  126. <tr>
  127. <td>
  128.  
  129. <font face="Arial" size="2">
  130. <b>The path you entered is incorrect.</b> You entered : "$dir"
  131. <p>
  132. Your root path is (UNIX): $ENV{DOCUMENT_ROOT}
  133. <p>
  134. Your root path is (WINDOWS): $ENV{PATH_TRANSLATED}
  135. <p>
  136. Your path should contain your root path followed by a slash followed by the
  137. destination folder's name. If you are on a WINDOWS server, each slash should
  138. be escaped. Eg. each seperator should look like this : \\\\
  139. <p>
  140. Sometimes, the root returned is not the full path to your web space. In this case
  141. you should either check with your host or if you are using an FTP client such as
  142. CuteFTP, change to the folder you are trying to upload to and look at the path you
  143. have taken. You can see this just above the list of files on your server.
  144. You must use the same path in the \$dir variable.
  145. </font>
  146.  
  147. </td>
  148. </tr>
  149. </table>
  150. ~;
  151.  
  152. &PrintFoot; # print the footer
  153. exit;
  154. }
  155.  
  156. use CGI; # load the CGI.pm module
  157. my $GET = new CGI; # create a new object
  158. my @VAL = $GET->param; #get all form field names
  159.  
  160. foreach(@VAL){
  161. $FORM{$_} = $GET->param($_); # put all fields and values in hash
  162. }
  163.  
  164. my @files;
  165. foreach(keys %FORM){
  166. if($_ =~ /^FILE/){
  167. push(@files, $_); # place the field NAME in an array
  168. }
  169. }
  170.  
  171. if(!$VAL[0]){
  172. # no form fields
  173. &PrintHead; #print the header
  174.  
  175. print qq~
  176. <table width="760">
  177. <tr>
  178. <td>
  179.  
  180. <font face="Arial" size="2">
  181. This script must be called using a form. Your form should point to this script. Your form tag must contain the following attributes :
  182. <p>
  183. &lt;form <font color="#FF0000">action</font>="$ScriptURL" <font color="#FF0000">method</font>="post" <font color="#FF0000">enctype</font>="multipart/form-data">
  184. <p>
  185. The <font color="#FF0000">method</font> must equal <font color="#FF0000">post</font> and the <font color="#FF0000">enctype</font> must equal <font color="#FF0000">multipart/form-data</font>. The <font color="#FF0000">action</font> has to point to this script (on your server). If you are reading this, copy and paste the example above. It has the correct values.
  186. </font>
  187.  
  188. </td>
  189. </tr>
  190. </table>
  191. ~;
  192.  
  193. &PrintFoot; # print the footer
  194. exit;
  195. }
  196.  
  197. # check domain
  198. if($domain =~ /\w+/){
  199. if($ENV{HTTP_REFERER} !~ /$domain/i){
  200. &PrintHead; #print the header
  201.  
  202. print qq~
  203. <table width="600">
  204. <tr>
  205. <td>
  206.  
  207. <font face="Arial" size="2">
  208. Invalid referrer.
  209. </font>
  210.  
  211. </td>
  212. </tr>
  213. </table>
  214. ~;
  215.  
  216. &PrintFoot; # print the footer
  217. exit;
  218. }
  219. }
  220.  
  221. my $failed; # results string = false
  222. my $selected; # num of files selected by user
  223.  
  224. ####################################################################
  225.  
  226. ####################################################################
  227.  
  228. foreach (@files){
  229. # upload each file, pass the form field NAME if it has a value
  230. if($GET->param($_)){
  231.  
  232. # if the form field contains a file name &psjs_upload subroutine
  233. # the file's name and path are passed to the subroutine
  234. $returned = &psjs_upload($_);
  235.  
  236. if($returned =~ /^Success/i){
  237. # if the $returned message begins with "Success" the upload was succssful
  238. # remove the word "Success" and any spaces and we're left with the filename
  239. $returned =~ s/^Success\s+//;
  240. push(@success, $returned);
  241. } else {
  242. # else if the word "success" is not returned, the message is the error encountered.
  243. # add the error to the $failed scalar
  244. $failed .= $returned;
  245. }
  246. $selected++; # increment num of files selected for uploading by user
  247. }
  248. }
  249.  
  250. if(!$selected){
  251. # no files were selected by user, so nothing is returned to either variable
  252. $failed .= qq~No files were selected for uploading~;
  253. }
  254.  
  255. # if no error message is return ed, the upload was successful
  256.  
  257. my ($fNames, $aa, $bb, @current, @currentfiles );
  258.  
  259. if($failed){
  260.  
  261. &PrintHead;
  262.  
  263. print qq~
  264. <table align="center" width="600">
  265. <tr>
  266. <td><font face="Arial" size="2">
  267.  
  268. One or more files <font color="#ff0000">failed</font> to upload. The reasons returned are:
  269. <p>
  270.  
  271. $failed
  272. ~;
  273.  
  274. if($success[0]){
  275. # send email if valid email was entered
  276. if(check_email($notify)){
  277.  
  278. # enter the message you would like to receive
  279. my $message = qq~
  280. The following files were uploaded to your server :
  281. ~;
  282.  
  283. $folder =~ s/(\/|\\)$//ig;
  284. foreach(@success){
  285. $message .= qq~
  286. $folder/$_
  287. ~;
  288. }
  289.  
  290. if($isUNIX){
  291. $CONFIG{mailprogram} = $send_mail_path;
  292. # enter your e-mail name here if you like
  293. # from e-mail, from name, to e-mail, to name, subject, body
  294. &send_mail($notify, 'File Upload', $notify, 'File Upload', 'Upload Notification', $message);
  295.  
  296. } else {
  297. $CONFIG{smtppath} = $smtp_path;
  298. &send_mail_NT($notify, 'Your Name', $notify, 'Your Name', 'Upload Notification', $message);
  299. }
  300. }
  301.  
  302. print qq~
  303. <p>
  304. The following files were <font color="#ff0000">successfully</font> uploaded :
  305. <p>
  306. ~;
  307. foreach(@success){
  308. print qq~
  309. $_<p>~;
  310. }
  311. }
  312.  
  313. print qq~
  314. </font></td>
  315. </tr>
  316. </table>
  317. ~;
  318.  
  319. &PrintFoot;
  320.  
  321. } else {
  322. # upload was successful
  323.  
  324. # add a link to the file
  325. $folder =~ s/(\/|\\)$//ig;
  326.  
  327. # send email if valid email was entered
  328. if(check_email($notify)){
  329.  
  330. # enter the message you would like to receive
  331. my $message = qq~
  332. The following files were uploaded to your server :
  333. ~;
  334.  
  335. foreach(@success){
  336. $message .= qq~
  337. $folder/$_
  338. ~;
  339. }
  340.  
  341. if($isUNIX){
  342. $CONFIG{mailprogram} = $send_mail_path;
  343. # enter your e-mail name here if you like
  344. # from e-mail, from name, to e-mail, to name, subject, body
  345. &send_mail($notify, 'File Upload', $notify, 'File Upload', 'Upload Notification', $message);
  346.  
  347. } else {
  348. $CONFIG{smtppath} = $smtp_path;
  349. &send_mail_NT($notify, 'Your Name', $notify, 'Your Name', 'Upload Notification', $message);
  350. }
  351. }
  352.  
  353. if($redirect){
  354. # redirect user
  355. print qq~Location: $redirect\n\n~;
  356. } else {
  357. # print success page
  358.  
  359. &PrintHead;
  360.  
  361. print qq~
  362. <table align="center" width="500">
  363. <tr>
  364. <th><font face="Arial" size="2"><font color="#ff0000">Success</font></font></th>
  365. </tr>
  366. <tr>
  367. <td><font face="Arial" size="2">The following files were successfully uploaded :
  368. <p>
  369. ~;
  370.  
  371. foreach(@success){
  372. print qq~
  373. $_<p>~;
  374. }
  375.  
  376. print qq~
  377. </font></td>
  378. </tr>
  379. </table>
  380. <br>
  381. ~;
  382.  
  383. if($print_contents){
  384. print qq~
  385. <table align="center" width="500">
  386. <tr><td><font face="Arial" size="2"><b>Current files in folder</b></td></tr>
  387. <tr>
  388. <td valign="top">
  389. <font face="Arial" size="2">
  390. ~;
  391.  
  392. opendir(DIR, "$dir");
  393. @current = readdir(DIR);
  394. closedir(DIR);
  395.  
  396. foreach(@current){
  397. unless($_ eq '.' || $_ eq '..' || -d qq~$dir/$_~){
  398. push(@currentfiles, $_);
  399. }
  400. }
  401.  
  402. @currentfiles = sort { uc($a) cmp uc($b) } @currentfiles;
  403.  
  404. for($aa = 0; $aa <= int($#currentfiles / 2); $aa++){
  405. print qq~
  406. <font color="#ff0000"><b>•</b>
  407. <a href="$folder/$currentfiles[$aa]" target="_blank">$currentfiles[$aa]</a></font><br>
  408. ~;
  409. }
  410.  
  411. print qq~</font></td><td valign="top"><font face="Arial" size="2">~;
  412.  
  413. for($bb = $aa; $bb < @currentfiles; $bb++){
  414. print qq~
  415. <font color="#ff0000"><b>•</b>
  416. <a href="$folder/$currentfiles[$bb]" target="_blank">$currentfiles[$bb]</a></font><br>
  417. ~;
  418. }
  419.  
  420.  
  421. print qq~
  422. </font></td>
  423. </tr>
  424. </table>~;
  425. }
  426.  
  427. print qq~
  428. <br>
  429. <center><font face="Arial" size="2">
  430. <a href="http://www.perlscriptsjavascripts.com/?ul">&copy; PerlScriptsJavaScripts.com</a>
  431. &nbsp; &nbsp;
  432. <a href="http://www.perlscriptsjavascripts.com/psjs_faqs/index.html?ul">F.A.Q.</a>
  433. &nbsp; &nbsp;
  434. <a href="http://www.perlscriptsjavascripts.com/perl/upload_lite/users_guide.html?ul">Users Guide</a>
  435. </font></center>
  436. ~;
  437.  
  438. &PrintFoot;
  439.  
  440. }
  441. }
  442.  
  443. ####################################################################
  444.  
  445. ####################################################################
  446.  
  447. sub psjs_upload {
  448.  
  449. my ( $type_ok, $file_contents, $buffer, $destination ); # declare some vars
  450.  
  451. my $file = $GET->param($_[0]); # get the FILE name. $_[0] is the arg passed
  452.  
  453. $destination = $dir;
  454.  
  455. my $limit = $max;
  456. $limit *= 1024; # convert limit from bytes to kilobytes
  457.  
  458. # create another instance of the $file var. This will allow the script to play
  459. # with the new instance, without effecting the first instance. This was a major
  460. # flaw I found in the psupload script. The author was replacing spaces in the path
  461. # with underscores, so the script could not find a file to upload. He blammed the
  462. # error on browser problems.
  463. my $fileName = $file;
  464.  
  465. # get the extension
  466. my @file_type = split(/\./, $fileName);
  467. # we can assume everything after the last . found is the extension
  468. my $file_type = $file_type[$#file_type];
  469.  
  470. # get the file name, this removes everything up to and including the
  471. # last slash found ( be it a forward or back slash )
  472. $fileName =~ s/^.*(\\|\/)//;
  473.  
  474. # remove all spaces from new instance of filename var
  475. $fileName =~ s/\s+//ig;
  476.  
  477. # check for any any non alpha numeric characters in filename (allow dots and dahses)
  478. $fileName =~ s/\./PsJsDoT/g;
  479. $fileName =~ s/\-/PsJsDaSh/g;
  480. if($fileName =~ /\W/){
  481. $fileName =~ s/\W/n/ig; # replace any bad chars with the letter "n"
  482. }
  483. $fileName =~ s/PsJsDoT/\./g;
  484. $fileName =~ s/PsJsDaSh/\-/g;
  485.  
  486. # if $file_type matchs one of the types specified, make the $type_ok var true
  487. for($b = 0; $b < @types; $b++){
  488. if($file_type =~ /^$types[$b]$/i){
  489. $type_ok++;
  490. }
  491. if($types[$b] eq "ALL"){
  492. $type_ok++; # if ALL keyword is found, increment $type_ok var.
  493. }
  494. }
  495.  
  496. # if ok, check if overwrite is allowed
  497. if($type_ok){
  498. if(!$overwrite){ # if $overwite = 0 or flase, rename file using the checkex sub
  499. $fileName = check_existence($destination,$fileName);
  500. }
  501. # create a new file on the server using the formatted ( new instance ) filename
  502. if(open(NEW, ">$destination$S{S}$fileName")){
  503. $VAR{err} .= $!;
  504. if($isWIN){binmode NEW;} # if it's a WIN server, switch to binary mode
  505. # start reading users HD 1 kb at a time.
  506. while (read($file, $buffer, 1024)){
  507. # print each kb to the new file on the server
  508. print NEW $buffer;
  509. }
  510. # close the new file on the server and we're done
  511. close NEW;
  512. } else {
  513. # return the server's error message if the new file could not be created
  514. return qq~Error: Could not open new file on server. $!~;
  515. }
  516.  
  517. # check limit hasn't just been overshot
  518. if(-s "$destination$S{S}$fileName" > $limit){ # -s is the file size
  519. unlink("$destination$S{S}$fileName"); # delete it if it's over the specified limit
  520. return qq~File exceeded limitations : $fileName~;
  521. }
  522.  
  523. check_size("$destination$S{S}$fileName")
  524.  
  525.  
  526. } else {
  527. return qq~Bad file type : $file_type~;
  528. }
  529.  
  530. # check if file has actually been uploaded, by checking the file has a size
  531. if(-s "$destination$S{S}$fileName"){
  532. return qq~Success $fileName~; #success
  533. } else {
  534. # delete the file as it has no content
  535. unlink("$destination$S{S}$fileName");
  536. # user probably entered an incorrect path to file
  537. return qq~Upload failed : No data in $fileName. No size on server's copy of file.
  538. Check the path entered. $VAR{err}~;
  539. }
  540. }
  541.  
  542. ####################################################################
  543.  
  544. ####################################################################
  545.  
  546. sub check_existence {
  547. # $dir,$filename,$newnum are the args passed to this sub
  548. my ($dir,$filename,$newnum) = @_;
  549.  
  550. my (@file_type, $file_type, $exists, $bareName);
  551. # declare some vars we will use later on in this sub always use paranthesis
  552. # when declaring more than one var! Some novice programmers will tell you
  553. # this is not necessary. Tell them to learn how to program.
  554.  
  555. if(!$newnum){$newnum = "0";} # new num is empty in first call, so set it to 0
  556.  
  557. # read dir and put all files in an array (list)
  558. opendir(DIR, "$dir");
  559. @existing_files = readdir(DIR);
  560. closedir(DIR);
  561.  
  562. # if the filename passed exists, set $exists to true or 1
  563. foreach(@existing_files){
  564. if($_ eq $filename){
  565. $exists = 1;
  566. }
  567. }
  568.  
  569. # if it exists, we need to rename the file being uploaded and then recheck it to
  570. # make sure the new name does not exist
  571. if($exists){
  572. $newnum++; # increment new number (add 1)
  573.  
  574. # get the extension
  575. @file_type = split(/\./, $filename); # split the dots and add inbetweens to a list
  576. # put the first element in the $barename var
  577. $bareName = $file_type[0];
  578. # we can assume everything after the last . found is the extension
  579. $file_type = $file_type[$#file_type];
  580. # $#file_type is the last element (note the pound or hash is used)
  581.  
  582. # remove all numbers from the end of the $bareName
  583. $bareName =~ s/\d+$//ig;
  584.  
  585. # concatenate a new name using the barename + newnum + extension
  586. $filename = $bareName . $newnum . '.' . $file_type;
  587.  
  588. # reset $exists to 0 because the new file name is now being checked
  589. $exists = 0;
  590.  
  591. # recall this subroutine
  592. &check_existence($dir,$filename,$newnum);
  593. } else {
  594. # the $filename, whether the first or one hundreth call, now does not exist
  595. # so return the name to be used
  596. return ($filename);
  597. }
  598. }
  599.  
  600. ####################################################################
  601.  
  602. ####################################################################
  603.  
  604. sub send_mail {
  605. my ($from_email, $from_name, $to_email, $to_name, $subject, $message ) = @_;
  606.  
  607. if(open(MAIL, "|$CONFIG{mailprogram} -t")) {
  608. print MAIL "From: $from_email ($from_name)\n";
  609. print MAIL "To: $to_email ($to_name)\n";
  610. print MAIL "Subject: $subject\n";
  611. print MAIL "$message\n\nSubmitter's IP Address : $ENV{REMOTE_ADDR}";
  612. close MAIL;
  613. return(1);
  614. } else {
  615. return;
  616. }
  617. }
  618.  
  619. ####################################################################
  620.  
  621. ####################################################################
  622.  
  623. sub send_mail_NT {
  624.  
  625. my ($from_email, $from_name, $to_email, $to_name, $subject, $message ) = @_;
  626.  
  627. my ($SMTP_SERVER, $WEB_SERVER, $status, $err_message);
  628. use Socket;
  629. $SMTP_SERVER = "$CONFIG{smtppath}";
  630.  
  631. # correct format for "\n"
  632. local($CRLF) = "\015\012";
  633. local($SMTP_SERVER_PORT) = 25;
  634. local($AF_INET) = ($] > 5 ? AF_INET : 2);
  635. local($SOCK_STREAM) = ($] > 5 ? SOCK_STREAM : 1);
  636. local(@bad_addresses) = ();
  637. $, = ', ';
  638. $" = ', ';
  639.  
  640. $WEB_SERVER = "$CONFIG{smtppath}\n";
  641. chop ($WEB_SERVER);
  642.  
  643. local($local_address) = (gethostbyname($WEB_SERVER))[4];
  644. local($local_socket_address) = pack('S n a4 x8', $AF_INET, 0, $local_address);
  645.  
  646. local($server_address) = (gethostbyname($SMTP_SERVER))[4];
  647. local($server_socket_address) = pack('S n a4 x8', $AF_INET, $SMTP_SERVER_PORT, $server_address);
  648.  
  649. # Translate protocol name to corresponding number
  650. local($protocol) = (getprotobyname('tcp'))[2];
  651.  
  652. # Make the socket filehandle
  653. if (!socket(SMTP, $AF_INET, $SOCK_STREAM, $protocol)) {
  654. return;
  655. }
  656.  
  657. # Give the socket an address
  658. bind(SMTP, $local_socket_address);
  659.  
  660. # Connect to the server
  661. if (!(connect(SMTP, $server_socket_address))) {
  662. return;
  663. }
  664.  
  665. # Set the socket to be line buffered
  666. local($old_selected) = select(SMTP);
  667. $| = 1;
  668. select($old_selected);
  669.  
  670. # Set regex to handle multiple line strings
  671. $* = 1;
  672.  
  673. # Read first response from server (wait for .75 seconds first)
  674. select(undef, undef, undef, .75);
  675. sysread(SMTP, $_, 1024);
  676. #print "<P>1:$_";
  677.  
  678. print SMTP "HELO $WEB_SERVER$CRLF";
  679. sysread(SMTP, $_, 1024);
  680. #print "<P>2:$_";
  681.  
  682. while (/(^|(\r?\n))[^0-9]*((\d\d\d).*)$/g) { $status = $4; $err_message = $3}
  683. if ($status != 250) {
  684. return;
  685. }
  686.  
  687. print SMTP "MAIL FROM:<$from_email>$CRLF";
  688.  
  689. sysread(SMTP, $_, 1024);
  690. #print "<P>3:$_";
  691. if (!/[^0-9]*250/) {
  692. return;
  693. }
  694.  
  695. # Tell the server where we're sending to
  696. print SMTP "RCPT TO:<$to_email>$CRLF";
  697. sysread(SMTP, $_, 1024);
  698. #print "<P>4:$_";
  699. /[^0-9]*(\d\d\d)/;
  700.  
  701. # Give the server the message header
  702. print SMTP "DATA$CRLF";
  703. sysread(SMTP, $_, 1024);
  704. #print "<P>5:$_";
  705. if (!/[^0-9]*354/) {
  706. return;
  707. }
  708.  
  709. $message =~ s/\n/$CRLF/ig;
  710.  
  711. print SMTP qq~From: $from_email ($from_name)$CRLF~;
  712. print SMTP qq~To: $to_email ($to_name)$CRLF~;
  713. if($cc){
  714. print SMTP "CC: $cc ($cc_name)\n";
  715. }
  716. print SMTP qq~Subject: $subject$CRLF$CRLF~;
  717. print SMTP qq~$message~;
  718.  
  719. print SMTP "$CRLF.$CRLF";
  720. sysread(SMTP, $_, 1024);
  721. #print "<P>6:$_";
  722. if (!/[^0-9]*250/) {
  723. return;
  724. } else {
  725. return(1);
  726. }
  727.  
  728. if (!shutdown(SMTP, 2)) {
  729. return;
  730. }
  731. }
  732.  
  733. ####################################################################
  734.  
  735. ####################################################################
  736.  
  737. sub PrintHead {
  738. print qq~Content-type: text/html\n\n~;
  739. print qq~
  740. <html>
  741. <title>PerlScriptsJavascript.com Free upload utility</title>
  742. <body bgcolor="#ffffff">
  743. ~;
  744. }
  745.  
  746. ####################################################################
  747.  
  748. ####################################################################
  749.  
  750. sub PrintFoot {
  751. print qq~
  752. </body>
  753. </html>
  754. ~;
  755. }
  756.  
  757. ####################################################################
  758.  
  759. ####################################################################
  760.  
  761. sub check_email {
  762. my($fe_email) = $_[0];
  763. if($fe_email) {
  764. if(($fe_email =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|(\.$)/) ||
  765. ($fe_email !~ /^.+@\[?(\w|[-.])+\.[a-zA-Z]{2,3}|[0-9]{1,3}\]?$/)) {
  766. return;
  767. } else { return(1) }
  768. } else {
  769. return;
  770. }
  771. }
  772. ###################################################################
  773. ###################################################################
  774.  
  775. sub check_size {
  776. # $dir,$filename,$newnum are the args passed to this sub
  777. my ($filename) = @_;
  778.  
  779. open ($filename,">-"); # use standard output as default
  780.  
  781. if($#ARGV > -1) { # but allow redirection to a file name
  782. close OFN;
  783. open ($filename,">$ARGV[0]");
  784. }
  785.  
  786. # print list header
  787.  
  788. print $filename sprintf("%-32s %-6s %-6s\n","Filename","Width","Height");
  789.  
  790. $w = "";
  791. $h = "";
  792.  
  793. foreach $fn (<*.gif>) { # list all .gif files
  794. if ($fn =~ /\.gif/) { # redundant for now, until I figure out .jpg format
  795. open (FH,$fn);
  796. binmode FH;
  797. read FH,$w,6; # skip first 6 bytes
  798. read FH,$w,2; # width
  799. read FH,$h,2; # height
  800. close FH;
  801. ($wl,$wh) = unpack("CC",$w); # there is probably a more
  802. ($hl,$hh) = unpack("CC",$h); # elegant way to do this
  803. $w = $wl + ($wh * 256);
  804. $h = $hl + ($hh * 256);
  805. print $filename sprintf("%-32s %6s %6s\n",$fn,$w,$h);
  806. close $filename;
  807. }
  808. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 10
Reputation: trickykid is an unknown quantity at this point 
Solved Threads: 0
trickykid trickykid is offline Offline
Newbie Poster

Re: modify script

 
0
  #2
Aug 24th, 2006
Originally Posted by clarkkent View Post
Hey guys. I have a prewritten script for uploading images to my server. It already checks filesize which i need. But i also need to check the image width and height to make sure it does not go over a certain size. I am not sure how to accomplish this as i am not very good with CGI. Would any of you mind helping me to accomplish this? Here is the script i have.
You could probably use ImageMagick to accomplish this. There's actually a ImageMagick CPAN module available out there.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC