11<?php
22
3+ /* Define Namespace */
4+ namespace RestJS \PhpRestApi \Controller ;
5+
36/* File Controller Class */
4- class FileController {
5-
6- function __construct () { }
7+ class File {
78
89 /* Check Method Function */
9- function fileController ($ method ) {
10+ public static function fileUpload ($ dir , $ method ) {
11+
1012 switch ($ method ) {
1113
1214 /* POST Method */
@@ -35,15 +37,9 @@ function fileController($method) {
3537
3638 /* Upload File */
3739 if (move_uploaded_file ($ _FILES ['upload ' ]['tmp_name ' ], $ url )){
38-
39- /* Check HTTPS */
40- if (isset ($ _SERVER ['HTTPS ' ])){
41- $ protocol = ($ _SERVER ['HTTPS ' ] && $ _SERVER ['HTTPS ' ] != "off " ) ? "https " : "http " ;
42- }
43- else { $ protocol = 'http ' ; }
4440
4541 /* Upload File Link */
46- $ url = $ protocol . " :// " . $ _SERVER [ ' SERVER_NAME ' ] ."/php-rest-api / " .$ url ;
42+ $ url = $ dir ."/ " .$ url ;
4743
4844 echo json_encode (array ('status ' =>'Success ' , 'message ' =>'File is successful uploaded. ' , 'file_url ' => $ url ));
4945
@@ -55,15 +51,9 @@ function fileController($method) {
5551
5652 /* Recive Delete File URL */
5753 $ data = json_decode (file_get_contents ('php://input ' ), true );
58-
59- /* Check HTTPS */
60- if (isset ($ _SERVER ['HTTPS ' ])){
61- $ protocol = ($ _SERVER ['HTTPS ' ] && $ _SERVER ['HTTPS ' ] != "off " ) ? "https " : "http " ;
62- }
63- else { $ protocol = 'http ' ; }
6454
6555 /* Remove Host Link in URL */
66- $ url = str_replace ($ protocol . " :// " . $ _SERVER [ ' SERVER_NAME ' ] ."/php-rest-api / " , "" ,$ data ['upload ' ]);
56+ $ url = str_replace ($ dir ."/ " , "" ,$ data ['upload ' ]);
6757
6858 /* Delete File */
6959 if (unlink ($ url )){
@@ -76,6 +66,4 @@ function fileController($method) {
7666
7767 }
7868 }
79- }
80-
81- ?>
69+ }
0 commit comments