Odyssey
stbanupload.prg
1 <?php
2  // This file will upload an estatement banner image for the credit union
3  // It will check image size - must match configured size in pdfdefs file
4 
5  require_once ("$admLibrary/ck_aticket.i"); // Just a precaution to make sure that it is processed through the cookie
6 
7 $dms_ok=array('action'=>'string','upload_file_name'=>'string');
8 dms_import($dms_ok);
9 
10  $self = "$PHP_SELF?ft={$ft}";
11  $saved_file = "$home_path/public_html/statban.jpg";
12 
13  // Check to make sure when they upload a file that a valid period is selected
14  switch ($action) {
15  case "Upload the File":
16 
17  // Don't allow a file size of 0 bytes
18  if (!is_uploaded_file($_FILES['upload_file']['tmp_name']) || ($_FILES['upload_file']['size'] < 1)) {
19  // A problem occurred record the information that I know and mail it to mark@homecu.net
20  // Gather msg together
21  switch ($_FILES['upload_file']['error']) {
22  case 0:
23  $up_err = "0: No error, the file was uploaded successfully";
24  break;
25  case 1:
26  $up_err = "1: The upload is larger than the amount allowable by the upload_max_filesize directive in the php.ini";
27  break;
28  case 2:
29  $up_err = "2: The upload is larger than the MAX_FILE_SIZE directive that was specified via html";
30  break;
31  case 3:
32  $up_err = "3: The file was only partially uploaded";
33  break;
34  case 3:
35  $up_err = "4: no file was uploaded";
36  break;
37  default:
38  $up_err = "NOT SET";
39  }
40  $msg = "
41 Upload File Error --\n
42 Client Information \n
43  Client Filename: {$_FILES['upload_file']['name']}\n
44  Client Filesize: {$_FILES['upload_file']['size']}\n
45  Client Filetype: {$_FILES['upload_file']['type']}\n\n
46  Client IP: {$_SERVER['REMOTE_ADDR']}\n\n
47 Web Server Information \n
48  Temp File Name - {$_FILES['upload_file']['tmp_name']}
49  Error Reported - $up_err\n\n
50 
51  ";
52  } else {
53 # test image size for exact conformance with size -
54  $imgstats = array();
55  $imgstats = getimagesize($_FILES['upload_file']['tmp_name']);
56  $imgW = $imgstats[0];
57  $imgH = $imgstats[1];
58  $imgT = $imgstats['mime'];
59  switch ($Cu) {
60  case "WEBER":
61  if ($imgW != 576 || $imgH != 115 || $imgT != "image/jpeg") {
62  $up_err = "Error Reported - Image is wrong type or wrong size";
63  $msg = "
64 Upload File Error --\n
65 Client Information \n
66  Client Filename: {$_FILES['upload_file']['name']}\n
67  Client Filesize: {$_FILES['upload_file']['size']}\n
68  Client Filetype: {$_FILES['upload_file']['type']}\n\n
69  Client IP: {$_SERVER['REMOTE_ADDR']}\n\n
70 Web Server Information \n
71  Temp File Name - {$_FILES['upload_file']['tmp_name']}
72  Error Reported - Image dimensions ( $imgW x $imgH ) are wrong.\n\n
73 
74  ";
75  }
76  break;
77  }
78  }
79  if ("$msg" != "") {
80  $notify = new ErrorMail;
81  $notify->line = __LINE__;
82  $notify->file = __FILE__;
83  $notify->callingfunction = __FUNCTION__;
84  $notify->sql = $msg;
85  $notify->cu = "$Cu";
86  $notify->survey = "";
87  $notify->mailto = "mark@homecu.net";
88  $notify->SendErr();
89  // IF we got here, the file is NOT an uploaded file report an error
90 
91  // An error may occur here if the file is too large, this can be set in the php.ini file the variable is upload_max_filesize
92  print <<< print_html
93  <center>
94  <br>
95  There was an error uploading the file <b>{$_FILES['upload_file']['name']}</b>.<br>
96  The error reported was: <b>$up_err</b>.<br>
97  Please retry uploading the file.<br>
98  If the problem persists call DMS and report the problem.
99 
100  </center>
101 print_html;
102  } else {
103  $real_name = "";
104  $find_ary = array("\\", "/", " ", ";"); // Create the list of characters for replacement
105  $rpl_ary = array("", "", "", ""); // Create the list of characters that will be replacing
106 
107  $real_name = str_replace($find_ary, $rpl_ary, $_FILES['upload_file']['name']);
108 
109  // Now move the file from the temporary position into the credit unions /tmp directory
110  if (!move_uploaded_file($_FILES['upload_file']['tmp_name'], $saved_file)) {
111  unlink ($_FILES['upload_file']['tmp_name']);
112  // Print error screen -- couldn't move file
113  print <<< html_text
114  <br><br>
115  Uh-oh, couldn't post the file where it belongs. Not sure what happened. Better call DMS.
116 html_text;
117  } else {
118  // File was moved change the mod settings
119  $rc = @chmod($saved_file, 0644);
120 
121  // Print the page text
122  print <<< html_text
123  <br><br>
124  Thank you for the upload.<br>
125  The file <b>{$_FILES['upload_file']['name']}</b> with a size of <b>{$_FILES['upload_file']['size']}</b> bytes was successfully uploaded.
126 html_text;
127  }
128 
129  }
130  break;
131  default:
132  // Print the form for uploading
133  // This is the default, which is to print the multi-part form for uploading
134  if ($msg != "") {
135  $print_msg = <<< set_msg
136  <tr><td colspan="2"><font color='red'>$msg</font></td></tr>
137 set_msg;
138  } else {
139  $print_msg ="";
140  }
141  print <<< form_data
142  <br>
143  <form method="post" action="$self" enctype="multipart/form-data">
144  <br>
145  <table cellpadding="4" align="CENTER" cellspacing="0" border="0" class="dtl">
146  $print_msg
147  <tr><th align="CENTER" colspan="2" class="bar">$Cu Statement Banner Upload</th></tr>
148  <tr><td>Choose a File:</td> <td><input type="file" name="upload_file" size="36" onChange="copyFile()"></td></tr>
149  <input type="hidden" name="upload_file_name" value="">
150  <tr><td align="CENTER" colspan="2"><input type="submit" name="action" value="Upload the File" onClick="return val_period();"></td></tr>
151  </table>
152  <br>
153  </form>
154  <script language="javascript">
155  <!--
156  function copyFile() {
157  document.forms[0].upload_file_name.value = document.forms[0].upload_file.value;
158  }
159  // -->
160  </script>
161 form_data;
162  break;
163  }