PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/class/genaral_file_class.php

https://bitbucket.org/itoxable/chiron-gaming
PHP | 196 lines | 164 code | 25 blank | 7 comment | 40 complexity | cde4c9b7b1c01ddd08661257e8f61184 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0
  1. <?
  2. class GeneralFileClass
  3. {
  4. var $ERROR = "";
  5. var $upload_path = "uploaded";
  6. function clear_error()
  7. {
  8. $this->ERROR = "";
  9. }
  10. function UploadGeneralFile($GeneralFileRadio,$general_file_hidden1,$http_general_file_name,$http_general_file_temp)
  11. {
  12. /* File upload starts */
  13. if($GeneralFileRadio == "Keep_General_File")
  14. {
  15. $filec1=$general_file_hidden1;
  16. }
  17. if($GeneralFileRadio == "Remove_General_File")
  18. {
  19. $filec1="";
  20. if(!empty($general_file_hidden1))
  21. {
  22. $filep=$general_file_hidden1;
  23. @unlink($this->upload_path."/".$filep);
  24. }
  25. }
  26. if(($GeneralFileRadio == "Change_General_File" || $GeneralFileRadio == ""))
  27. {
  28. $filec1 = $http_general_file_name;
  29. #####################################
  30. $temp = $http_general_file_temp;
  31. $Filecs = $http_general_file_name;
  32. $Filecs = ereg_replace(" ", "_", $Filecs);
  33. $Filecs = ereg_replace("%20", "_", $Filecs);
  34. $Filecs = preg_replace("/[^-\._a-zA-Z0-9]/", "", $Filecs);
  35. $uniq = uniqid("");
  36. $filec1 = $uniq."_".$Filecs;
  37. $upload = $this->upload_path."/".$filec1;
  38. copy($temp, $upload);
  39. if(!empty($general_file_hidden1))
  40. {
  41. $filep=$general_file_hidden1;
  42. @unlink($this->upload_path."/".$filep);
  43. }
  44. }
  45. return $filec1;
  46. /* File upload ends */
  47. }
  48. /* Checking of Document Starts */
  49. function CheckGeneralFile($GeneralFileRadio,$http_general_file_name,$http_general_file_temp,$http_general_file_type,$http_general_file_size,$allowed_types,$allowed_types_lebel,$Filelebel="",$mandatory="N",$bytesize=3)
  50. {
  51. if(!empty($Filelebel))
  52. $Filelebel =" for <span class=red>".$Filelebel."</span>";
  53. if($mandatory=="Y")
  54. {
  55. if($GeneralFileRadio == "Remove_General_File")
  56. {
  57. $err_msgs .= "<li>File should not be removed $Filelebel!</li>";
  58. }
  59. }
  60. if ($GeneralFileRadio == "Change_General_File" || $GeneralFileRadio == "")
  61. {
  62. $filec1 = $http_general_file_name;
  63. if(!empty($filec1)) ## CHECKING IMAGE
  64. {
  65. $general_file_size=$http_general_file_size;
  66. $general_file_type=$http_general_file_type;
  67. $temp = $http_general_file_temp;
  68. if(empty($bytesize))
  69. $bytesize=3;
  70. $size_limit=$bytesize*1048576; /* set size limit in Bytes */
  71. $http_general_file_name_arr=explode(".",$http_general_file_name);
  72. $general_file_type_dot=$http_general_file_name_arr[count($http_general_file_name_arr)-1];
  73. $general_file_type_dot=".".$general_file_type_dot;
  74. if($general_file_size!="0")
  75. {
  76. if ($general_file_size < $size_limit)
  77. {
  78. if (!in_array($general_file_type,$allowed_types))
  79. {
  80. $err_msgs .= "<li>Files of type <b>$general_file_type</b> are not allowed to be uploaded!</li>";
  81. }
  82. elseif (!in_array($general_file_type_dot,$allowed_types_lebel))
  83. {
  84. $err_msgs .= "<li>Files of type <b>$general_file_type</b> are not allowed to be uploaded!</li>";
  85. }
  86. }
  87. else
  88. {
  89. $err_msgs .= "<li>The file <span class=red>$filec1</span> you selected to upload is too large to be uploaded $Filelebel!</li>";
  90. }
  91. }
  92. else if($general_file_size=="0")
  93. {
  94. $err_msgs .= "<li>The file <span class=red>$filec1</span> was not found $Filelebel!</li>";
  95. }
  96. } ## END OF CHECKING IMAGE
  97. if($mandatory=="Y")
  98. {
  99. if( ($GeneralFileRadio == "Change_General_File" || $GeneralFileRadio == "" ) && empty($filec1))
  100. {
  101. $err_msgs .= "<li>No File uploaded $Filelebel!</li>";
  102. }
  103. }
  104. elseif($mandatory=="N")
  105. {
  106. if ($GeneralFileRadio == "Change_General_File" && empty($filec1))
  107. {
  108. $err_msgs .= "<li>No File uploaded $Filelebel!</li>";
  109. }
  110. }
  111. }
  112. return $err_msgs;
  113. }
  114. /* Checking of Document Ends */
  115. /* Display of Upload Control starts */
  116. function DisplayGeneralFileControl($general_file_lebel_name,$general_file_control_name,$general_file_control_val,$general_file_hidden_name,$general_file_radio_name,$mandatory="Y",$display_general_file="Y",$allowed_types,$generalfilesize=3)
  117. {
  118. ?>
  119. <tr bgcolor="#FFFFFF">
  120. <td valign="top" class="body" colspan="2" align="left">
  121. <b>Upload
  122. <?
  123. $allowed_types_display_str="";
  124. foreach($allowed_types as $val)
  125. {
  126. $allowed_types_display_str.=$val.",";
  127. }
  128. echo substr($allowed_types_display_str,0,-1);
  129. ?> file
  130. . Upload file should not exceed <?=$generalfilesize?>Mb.</b>
  131. </td>
  132. </tr>
  133. <tr bgcolor="#FFFFFF">
  134. <td class="body" valign="top"><?=$general_file_lebel_name?>: <? if($mandatory=="Y") {?><span class="red">*</span><? }?></td>
  135. <td valign="top">
  136. <?
  137. if (strlen($general_file_control_val)!=0 && file_exists($this->upload_path."/".$general_file_control_val))
  138. {
  139. if($display_general_file=="Y")
  140. {
  141. $DocPath=$this->upload_path."/".$general_file_control_val;
  142. ?>
  143. <a href="<? echo $DocPath;?>" class="links"><? echo substr($general_file_control_val,14);?></a><BR>
  144. <?
  145. }
  146. ?>
  147. <input type="radio" name="<?=$general_file_radio_name?>" value="Keep_General_File" checked >
  148. <span class="body">Keep File</span>
  149. <?
  150. if($mandatory!="Y")
  151. {
  152. ?>
  153. <input type="radio" name="<?=$general_file_radio_name?>" value="Remove_General_File" >
  154. <span class="body">Remove File</span>
  155. <?
  156. }
  157. ?>
  158. <input type="radio" name="<?=$general_file_radio_name?>" value="Change_General_File">
  159. <span class="body">Change File</span><br>
  160. <INPUT type="hidden" name="<?=$general_file_hidden_name?>" value="<? echo $general_file_control_val; ?>">
  161. <?
  162. }
  163. ?>
  164. <INPUT type="file" name="<?=$general_file_control_name?>" class="form" size="30">
  165. </td>
  166. </tr>
  167. <?
  168. }
  169. /* Display of Upload Control Ends */
  170. }
  171. ?>