login  Naam:   Wachtwoord: 
Registreer je!
 Forum

Dirs fout met upload via absolute path

Offline BladiN - 22/11/2004 20:47 (laatste wijziging 22/11/2004 20:50)
Avatar van BladiNGouden medailleGouden medaille

Grafische gevorderde
Ik heb het volgende upload script:
  1. <?
  2. class upload {
  3.  
  4. var $temp_file_name = "";
  5. var $file_name = "";
  6. var $upload_dir = "";
  7. var $upload_log_dir = "";
  8. var $file_prefix = "";
  9. var $max_file_size = "";
  10. var $max_width = "";
  11. var $max_height = "";
  12. var $thumb_width = "";
  13. var $thumb_height = "";
  14. var $ext_array = array();
  15. var $sess_id = "";
  16.  
  17. function valExtension() {
  18. $file_name = trim($this->file_name);
  19. $extension = strtolower(strrchr($file_name, "."));
  20. $ext_array = $this->ext_array;
  21. $ext_count = count($ext_array);
  22.  
  23. if(!$file_name) {
  24. return false;
  25. } else {
  26. if(empty($ext_array)) {
  27. return true;
  28. } else {
  29. foreach($ext_array as $val) {
  30. $first_char = substr($val, 0, 1);
  31. if($first_char <> ".") {
  32. $extensions[] = "." . strtolower($val);
  33. } else {
  34. $extensions[] = strtolower($val);
  35. }
  36. }
  37.  
  38. foreach($extensions as $val) {
  39. if($val == $extension) {
  40. $valid_extension = true;
  41. }
  42. }
  43.  
  44. if($valid_extension == true) {
  45. return true;
  46. } else {
  47. return false;
  48. }
  49. }
  50. }
  51. }
  52.  
  53. function valSize() {
  54. $temp_file_name = trim($this->temp_file_name);
  55. $max_file_size = trim($this->max_file_size);
  56.  
  57. if($temp_file_name) {
  58. $size = filesize($temp_file_name);
  59. if($size > $max_file_size) {
  60. return false;
  61. } else {
  62. return true;
  63. }
  64. } else {
  65. return false;
  66. }
  67. }
  68.  
  69. function fileExist() {
  70. $file_name = trim($this->file_name);
  71. $upload_dir = $this->getUploadDir();
  72.  
  73. if($upload_dir == false) {
  74. return true;
  75. } else {
  76. $file = $upload_dir . $file_name;
  77. if(file_exists($file)) {
  78. return true;
  79. } else {
  80. return false;
  81. }
  82. }
  83. }
  84.  
  85. function fileSizes() {
  86. $temp_file_name = trim($this->temp_file_name);
  87.  
  88. if($this->max_width) {
  89. $file = imagecreatefromjpeg($temp_file_name);
  90.  
  91. $x = imagesx($file);
  92. $y = imagesy($file);
  93.  
  94. if($x > $this->max_width || $y > $this->max_width) {
  95. return false;
  96. } else {
  97. return true;
  98. }
  99.  
  100. imagedestroy($file);
  101. return true;
  102. } else {
  103. return false;
  104. }
  105. }
  106.  
  107. function getFileSize() {
  108. $temp_file_name = trim($this->temp_file_name);
  109. $kb = 1024;
  110. $mb = 1024 * $kb;
  111.  
  112. if($temp_file_name) {
  113. $size = filesize($temp_file_name);
  114. if($size < $kb) {
  115. $file_size = $size . "Bytes";
  116. } elseif($size < $mb) {
  117. $file_size = $size . "Kb";
  118. } else {
  119. $file_size = $size . "Mb";
  120. }
  121. } else {
  122. $file_size = header("Location: error.php?eid=5");
  123. }
  124.  
  125. return $file_size;
  126.  
  127. }
  128.  
  129. function getMaxSize() {
  130. $max_file_size = trim($this->max_file_size);
  131. $kb = 1024;
  132. $mb = 1024 * $kb;
  133.  
  134. if($max_file_size) {
  135. if($max_file_size < $kb) {
  136. $max_file_size = $max_file_size . "Bytes";
  137. } elseif($max_file_size < $mb) {
  138. $final = round($max_file_size/$kb, 2);
  139. $max_file_size = $final . "Kb";
  140. } else {
  141. $final = round($max_file_size/$mb, 2);
  142. $max_file_size = $final . "Mb";
  143. }
  144. } else {
  145. $max_file_size = header("Location: error.php?eid=5");
  146. }
  147.  
  148. return $max_file_size;
  149.  
  150. }
  151.  
  152. function getUploadDir() {
  153. print('blaat');
  154. $upload_dir = trim($this->upload_dir);
  155.  
  156. if($upload_dir) {
  157. $dir_lenght = strlen($upload_dir);
  158. $last_slash = substr($upload_dir, $dir_lenght-1, 1);
  159.  
  160. if($last_slash <> "/") {
  161. $upload_dir = $upload_dir . "/";
  162. }
  163.  
  164. $handle = @opendir($upload_dir);
  165. $handle = @opendir($upload_log_dir);
  166. if($handle) {
  167. closedir($handle);
  168. } else {
  169. mkdir("/home/httpd/vhosts/picturestorage.nl/httpdocs/web/".$this->sess_id."/thumb", 0777);
  170. $upload_log_dir = false;
  171. }
  172. } else {
  173. $upload_dir = false;
  174. }
  175.  
  176. return $upload_dir;
  177. }
  178.  
  179. function getUploadLogDir() {
  180. $upload_log_dir = trim($this->upload_log_dir);
  181.  
  182. if($upload_log_dir) {
  183. $dir_lenght = strlen($upload_log_dir);
  184. $last_slash = substr($upload_log_dir, $dir_lenght-1, 1);
  185.  
  186. if($last_slash <> "/") {
  187. $upload_log_dir = $upload_log_dir . "/";
  188. }
  189.  
  190. $handle = @opendir($upload_log_dir);
  191. if($handle) {
  192. closedir($handle);
  193. } else {
  194. mkdir("/home/httpd/vhosts/picturestorage.nl/httpdocs/web/".$this->sess_id."/logs", 0777);
  195. $upload_log_dir = false;
  196. }
  197. } else {
  198. $upload_log_dir = true;
  199. }
  200.  
  201. return $upload_log_dir;
  202. }
  203.  
  204. function fileRename() {
  205. $file_name = trim(strtolower($this->file_name));
  206.  
  207. $split_file = explode(".", $file_name);
  208. $ext = array_pop($split_file);
  209. $file_name = $this->file_prefix . $this->sess_id . "." . $ext;
  210.  
  211. return $file_name;
  212. }
  213.  
  214. function createThumb() {
  215. $upload_dir = $this->getUploadDir();
  216. $file_name = $this->fileRename();
  217. $mwidth = $this->thumb_width;
  218. $mheight = $this->thumb_height;
  219. $split_file = explode(".", $file_name);
  220. $ext = array_pop($split_file);
  221.  
  222. $thumb_name = "thumb/" . $this->file_prefix . $this->sess_id . ".". $ext;
  223.  
  224. if($ext == "jpg" || $ext == "jpeg") {
  225. $thumb = imagecreatefromjpeg($upload_dir . $file_name);
  226.  
  227. $thumbx = imagesx($thumb);
  228. $thumby = imagesy($thumb);
  229.  
  230. if($mwidth <= 0 || $mwidth >= $thumbx) {
  231. $mwidth = $thumbx;
  232. }
  233.  
  234. $mheight = ($thumbx*($mwidth/$thumbx));
  235.  
  236. if($thumbx > $thumby) {
  237. $width = $mwidth;
  238. $height = ($thumby*($mheight/$thumbx));
  239. }
  240.  
  241. if($thumbx < $thumby) {
  242. $width = ($thumbx*($mwidth/$thumby));
  243. $height = $mheight;
  244. }
  245.  
  246. if($thumbx == $thumby) {
  247. $width = $mwidht;
  248. $height = $mheight;
  249. }
  250.  
  251. $thumbImg = imagecreatetruecolor($width, $height);
  252. imagecopyresampled($thumbImg, $thumb, 0, 0, 0, 0, $width, $height, $thumbx, $thumby);
  253. imagejpeg($thumbImg, $upload_dir . $thumb_name, 100);
  254.  
  255. imagedestroy($thumb);
  256. imagedestroy($thumbImg);
  257. } elseif ($ext == "png") {
  258. $thumb = imagecreatefrompng($upload_dir . $file_name);
  259.  
  260. $thumbx = imagesx($thumb);
  261. $thumby = imagesy($thumb);
  262.  
  263. if($mwidth <= 0 || $mwidth >= $thumbx) {
  264. $mwidth = $thumbx;
  265. }
  266.  
  267. $mheight = ($thumbx*($mwidth/$thumbx));
  268.  
  269. if($thumbx > $thumby) {
  270. $width = $mwidth;
  271. $height = ($thumby*($mheight/$thumbx));
  272. }
  273.  
  274. if($thumbx < $thumby) {
  275. $width = ($thumbx*($mwidth/$thumby));
  276. $height = $mheight;
  277. }
  278.  
  279. if($thumbx == $thumby) {
  280. $width = $mwidht;
  281. $height = $mheight;
  282. }
  283.  
  284. $thumbImg = imagecreatetruecolor($width, $height);
  285. imagecopyresampled($thumbImg, $thumb, 0, 0, 0, 0, $width, $height, $thumbx, $thumby);
  286. imagejpeg($thumbImg, $upload_dir . $thumb_name, 100);
  287.  
  288. imagedestroy($thumb);
  289. imagedestroy($thumbImg);
  290. }
  291. }
  292.  
  293. function noValidation() {
  294. $temp_file_name = trim($this->temp_file_name);
  295. $file_name = $this->fileRename();
  296. $upload_dir = $this->getUploadDir();
  297. $upload_log_dir = $this->getUploadLogDir();
  298. $file_size = $this->getFileSize();
  299. $ip = trim($_SERVER['REMOTE_ADDR']);
  300. $cpu = gethostbyaddr($ip);
  301. $m = date("m");
  302. $d = date("d");
  303. $y = date("Y");
  304. $date = date("m/d/Y");
  305. $time = date("H:i:s");
  306.  
  307. if($upload_dir == false || $upload_log_dir == false) {
  308. return false;
  309. } else {
  310. if(is_uploaded_file($temp_file_name)) {
  311. if(move_uploaded_file($temp_file_name, $upload_dir . $file_name)) {
  312. $log = $upload_log_dir . $y . "_" . $m . "_" . $d . ".txt";
  313. $fp = fopen($log, "a+");
  314. fwrite($fp, $this->sess_id . "|" . $ip . "-" . $cpu . "|" . $file_name . "|" . $file_size . "|" . $date . "|" . $time . "<br />");
  315. fclose($fp);
  316. if($stat == true) {
  317. $this->createThumb();
  318. }
  319. mysql_query("UPDATE storage SET foto = '".$file_name."', updatum = '".$date." ".$time."' WHERE gebruiker = '".$this->sess_id."'") or die (mysql_error());
  320. return true;
  321. } else {
  322. return false;
  323. }
  324. } else {
  325. return false;
  326. }
  327. }
  328. }
  329.  
  330. function fileValidation($stat) {
  331. $temp_file_name = trim($this->temp_file_name);
  332. $file_name = $this->fileRename();
  333. $upload_dir = $this->getUploadDir();
  334. $upload_log_dir = $this->getUploadLogDir();
  335. $file_size = $this->getFileSize();
  336. $ip = trim($_SERVER['REMOTE_ADDR']);
  337. $cpu = gethostbyaddr($ip);
  338. $m = date("m");
  339. $d = date("d");
  340. $y = date("Y");
  341. $date = date("m/d/Y");
  342. $time = date("H:i:s");
  343. $existing_file = $this->fileExist();
  344. $valid_ext = $this->valExtension();
  345.  
  346. if($upload_dir == false || $upload_log_dir == false) {
  347. return false;
  348. print('a');
  349. } elseif ($existing_file == true ||$valid_ext == false) {
  350. return false;
  351. print('b');
  352. } else {
  353. print('c');
  354. if(is_uploaded_file($temp_file_name)) {
  355. if(move_uploaded_file($temp_file_name, $upload_dir . $file_name)) {
  356. $log = $upload_log_dir . $y . "_" . $m . "_" . $d . ".txt";
  357. $fp = fopen($log, "a+");
  358. fwrite($fp,$this->sess_id . "|" . $ip . "-" . $cpu . "|" . $file_name . "|" . $file_size . "|" . $date . "|" . $time . "<br />");
  359. fclose($fp);
  360. if($stat == true) {
  361. $this->createThumb();
  362. }
  363. mysql_query("UPDATE storage SET foto = '".$file_name."', updatum = '".$date." ".$time."' WHERE gebruiker = '".$this->sess_id."'") or die (mysql_error());
  364. return true;
  365. } else {
  366. return false;
  367. }
  368. } else {
  369. return false;
  370. }
  371. }
  372. }
  373. }
  374.  
  375. $upload = new upload;
  376.  
  377. chmod("/home/httpd/vhosts/picturestorage.nl/httpdocs/web/".$naam, 0777);
  378. if(is_uploaded_file($_FILES['bestand']['tmp_name'])) {
  379. $upload->temp_file_name = trim($_FILES['bestand']['tmp_name']);
  380. $upload->file_name = trim(strtolower($_FILES['bestand']['name']));
  381. $upload->upload_dir = "/home/httpd/vhosts/picturestorage.nl/httpdocs/web/".$naam;
  382. $upload->upload_log_dir = "/home/httpd/vhosts/picturestorage.nl/httpdocs/web/".$naam."/logs";
  383. $upload->file_prefix = "foto_";
  384. $upload->thumb_width = 250;
  385. $upload->thumb_height = 150;
  386. $upload->ext_array = array(".jpg", ".jpeg", ".png");
  387. $upload->sess_id = $naam;
  388.  
  389. $uploadFile = $upload->fileValidation(true);
  390. }
  391. ?>


hij moet dus via een absolute path uploaden (maar dat doet hij dus niet :S, als ik gewoon web zou doen werkt het wel maar dan komt hij in n verkeerde map) dus nou zou ik willen weten hoe ik dat op kan lossen? hij maakt die dirs dus al niet aan. ziet iemand de fout?

0 antwoorden

Gesponsorde links
Er zijn nog geen reacties op dit bericht.
Dit onderwerp is gesloten.
Actieve forumberichten
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.261s