Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Refactor repeated function urlfilesize() into its own file.

  • Loading branch information...
commit 07326f1e877fd96eb05ca20813f93b9419f65d5d 1 parent 5851d65
Ross Lagerwall authored
25 addTopicExecute.php
@@ -14,30 +14,7 @@
14 14 include_once("class.User.php");
15 15 session_start();
16 16
17   - function urlfilesize($url,$thereturn)
18   - {
19   - if (substr($url,0,4)=='http')
20   - {
21   - $x = array_change_key_case(get_headers($url, 1),CASE_LOWER);
22   - $x = $x['content-length'];
23   - }
24   - else
25   - {
26   - $x = @filesize($url);
27   - }
28   - if (!$thereturn)
29   - {
30   - return $x;
31   - }
32   - elseif ($thereturn == 'mb')
33   - {
34   - return round($x / (1024*1024),2);
35   - }
36   - elseif ($thereturn == 'kb')
37   - {
38   - return round($x / (1024),0);
39   - }
40   - }
  17 + include_once("function.misc.php");
41 18
42 19 $total = trim(file_get_contents("db/topicNo.dat"));
43 20 file_put_contents("db/topicNo.dat",($total+1));
26 editExecute.php
@@ -14,31 +14,7 @@ function isValidEmail($email)
14 14 }
15 15 }
16 16
17   -
18   - function urlfilesize($url,$thereturn)
19   - {
20   - if (substr($url,0,4)=='http')
21   - {
22   - $x = array_change_key_case(get_headers($url, 1),CASE_LOWER);
23   - $x = $x['content-length'];
24   - }
25   - else
26   - {
27   - $x = @filesize($url);
28   - }
29   - if (!$thereturn)
30   - {
31   - return $x;
32   - }
33   - elseif ($thereturn == 'mb')
34   - {
35   - return round($x / (1024*1024),2);
36   - }
37   - elseif ($thereturn == 'kb')
38   - {
39   - return round($x / (1024),0);
40   - }
41   - }
  17 + include_once("function.misc.php");
42 18
43 19 include_once("class.User.php");
44 20 session_start();
25 editPostExecute.php
@@ -8,30 +8,7 @@
8 8 include_once("class.User.php");
9 9 session_start();
10 10
11   - function urlfilesize($url,$thereturn)
12   - {
13   - if (substr($url,0,4)=='http')
14   - {
15   - $x = array_change_key_case(get_headers($url, 1),CASE_LOWER);
16   - $x = $x['content-length'];
17   - }
18   - else
19   - {
20   - $x = @filesize($url);
21   - }
22   - if (!$thereturn)
23   - {
24   - return $x;
25   - }
26   - elseif ($thereturn == 'mb')
27   - {
28   - return round($x / (1024*1024),2);
29   - }
30   - elseif ($thereturn == 'kb')
31   - {
32   - return round($x / (1024),0);
33   - }
34   - }
  11 + include_once("function.misc.php");
35 12
36 13 $str = "";
37 14 $fileC = file("db/Topics/".$_GET['topicId']."/posts.dat",FILE_IGNORE_NEW_LINES);
29 function.misc.php
... ... @@ -0,0 +1,29 @@
  1 +<?php
  2 + /* Return the size of a remote url or a local file specified by $url.
  3 + $thereturn specifies the unit returned (either bytes "", MiB "mb" or KiB
  4 + "kb"). */
  5 + function urlfilesize($url,$thereturn)
  6 + {
  7 + if (substr($url,0,4)=='http')
  8 + {
  9 + $x = array_change_key_case(get_headers($url, 1),CASE_LOWER);
  10 + $x = $x['content-length'];
  11 + }
  12 + else
  13 + {
  14 + $x = @filesize($url);
  15 + }
  16 + if (!$thereturn)
  17 + {
  18 + return $x;
  19 + }
  20 + elseif ($thereturn == 'mb')
  21 + {
  22 + return round($x / (1024*1024),2);
  23 + }
  24 + elseif ($thereturn == 'kb')
  25 + {
  26 + return round($x / (1024),0);
  27 + }
  28 + }
  29 +?>
25 pmComposeExecute.php
@@ -9,30 +9,7 @@
9 9
10 10 include("common.php");
11 11
12   - function urlfilesize($url,$thereturn)
13   - {
14   - if (substr($url,0,4)=='http')
15   - {
16   - $x = array_change_key_case(get_headers($url, 1),CASE_LOWER);
17   - $x = $x['content-length'];
18   - }
19   - else
20   - {
21   - $x = @filesize($url);
22   - }
23   - if (!$thereturn)
24   - {
25   - return $x;
26   - }
27   - elseif ($thereturn == 'mb')
28   - {
29   - return round($x / (1024*1024),2);
30   - }
31   - elseif ($thereturn == 'kb')
32   - {
33   - return round($x / (1024),0);
34   - }
35   - }
  12 + include_once("function.misc.php");
36 13
37 14 $fileC = file("db/PMs/".$_GET['userId'].".dat");
38 15
26 postExecute.php
... ... @@ -1,31 +1,7 @@
1 1 <?php
2 2 $_POST['reply'] = str_replace("~","",$_POST['reply']);
3 3
4   - function urlfilesize($url,$thereturn)
5   - {
6   - if (substr($url,0,4)=='http')
7   - {
8   - $x = array_change_key_case(get_headers($url, 1),CASE_LOWER);
9   - $x = $x['content-length'];
10   - }
11   - else
12   - {
13   - $x = @filesize($url);
14   - }
15   - if (!$thereturn)
16   - {
17   - return $x;
18   - }
19   - elseif ($thereturn == 'mb')
20   - {
21   - return round($x / (1024*1024),2);
22   - }
23   - elseif ($thereturn == 'kb')
24   - {
25   - return round($x / (1024),0);
26   - }
27   - }
28   -
  4 + include_once("function.misc.php");
29 5 include_once("common.php");
30 6
31 7 $fh = fopen("db/Topics/".$_GET['topicId']."/posts.dat","a");

0 comments on commit 07326f1

Please sign in to comment.
Something went wrong with that request. Please try again.