@@ -149,13 +149,13 @@ static public function HeadersSent()
149149 * include if file exist
150150 *
151151 * @param string $path
152- * - [do not include base path ]
152+ * - [base path will be automatically added ]
153153 *
154154 * @return void
155155 */
156156 static public function include ($ path )
157157 {
158- $ fullPath = trim ( self ::getBasePath ($ path), ' \/ ' );
158+ $ fullPath = self ::getBasePath ($ path );
159159
160160 if (self ::exists ($ fullPath )){
161161 include $ fullPath ;
@@ -166,13 +166,13 @@ static public function include($path)
166166 * include once if file exist
167167 *
168168 * @param string $path
169- * - [do not include base path ]
169+ * - [base path will be automatically added ]
170170 *
171171 * @return void
172172 */
173173 static public function includeOnce ($ path )
174174 {
175- $ fullPath = trim ( self ::getBasePath ($ path), ' \/ ' );
175+ $ fullPath = self ::getBasePath ($ path );
176176
177177 if (self ::exists ($ fullPath )){
178178 include_once $ fullPath ;
@@ -183,13 +183,13 @@ static public function includeOnce($path)
183183 * require if file exist
184184 *
185185 * @param string $path
186- * - [do not include base path ]
186+ * - [base path will be automatically added ]
187187 *
188188 * @return void
189189 */
190190 static public function require ($ path )
191191 {
192- $ fullPath = trim ( self ::getBasePath ($ path), ' \/ ' );
192+ $ fullPath = self ::getBasePath ($ path );
193193
194194 if (self ::exists ($ fullPath )){
195195 require $ fullPath ;
@@ -200,13 +200,13 @@ static public function require($path)
200200 * require_once if file exist
201201 *
202202 * @param string $path
203- * - [do not include base path ]
203+ * - [base path will be automatically added ]
204204 *
205205 * @return void
206206 */
207207 static public function requireOnce ($ path )
208208 {
209- $ fullPath = trim ( self ::getBasePath ($ path), ' \/ ' );
209+ $ fullPath = self ::getBasePath ($ path );
210210
211211 if (self ::exists ($ fullPath )){
212212 require_once $ fullPath ;
@@ -277,7 +277,7 @@ static public function sizeToBytes($size = '1mb')
277277 * Get file modification time
278278 *
279279 * @param string|null $path
280- * - [do not include base path ]
280+ * - [base path will be automatically added ]
281281 *
282282 * @return int|bool
283283 */
@@ -296,7 +296,7 @@ static public function getFiletime($path = null)
296296 * Get file modification time
297297 *
298298 * @param string|null $path
299- * - [do not include base path ]
299+ * - [base path will be automatically added ]
300300 *
301301 * @return int|bool
302302 */
@@ -759,23 +759,38 @@ static public function formatNumberToNearestThousand(float|int $number = 0)
759759
760760 return $ number ;
761761 }
762+
763+ /**
764+ * File exist and not a directory
765+ *
766+ * @param string|null $path
767+ * - [full path to file]
768+ *
769+ * @return bool
770+ */
771+ static public function exists ($ path = null )
772+ {
773+ return !is_dir ($ path ) && file_exists ($ path );
774+ }
762775
763776 /**
764777 * Unlink File from Server
765778 *
766- * @param string $fileToUnlink
767- * - [full path to file ]
779+ * @param string $pathToFile
780+ * - [base path will be automatically added ]
768781 *
769- * @param string|null $checkFile
782+ * @param string|null $fileName
770783 * - [optional] file name. <avatar.png>
771784 *
772785 * @return void
773786 */
774- static public function unlinkFile (string $ fileToUnlink , $ fileName = null )
787+ static public function unlink (string $ pathToFile , $ fileName = null )
775788 {
776- if (self ::exists ($ fileToUnlink )){
777- if (basename ($ fileToUnlink ) != basename ((string ) $ fileName )){
778- @unlink ($ fileToUnlink );
789+ $ fullPath = self ::getBasePath ($ pathToFile );
790+
791+ if (self ::exists ($ fullPath )){
792+ if (basename ($ fullPath ) != basename ((string ) $ fileName )){
793+ @unlink ($ fullPath );
779794 }
780795 }
781796 }
@@ -784,7 +799,7 @@ static public function unlinkFile(string $fileToUnlink, $fileName = null)
784799 * Convert json data to array|object
785800 *
786801 * @param string $path
787- * - [full path to file ]
802+ * - [base path will be automatically added ]
788803 *
789804 * @param bool $format
790805 * - [optional] `true` will convert to an array
@@ -793,8 +808,10 @@ static public function unlinkFile(string $fileToUnlink, $fileName = null)
793808 */
794809 static public function convertJsonData ($ path , $ format = true )
795810 {
796- if (self ::exists ($ path )){
797- return json_decode (file_get_contents ($ path ), $ format );
811+ $ fullPath = self ::getBasePath ($ path );
812+
813+ if (self ::exists ($ fullPath )){
814+ return json_decode (file_get_contents ($ fullPath ), $ format );
798815 }
799816 }
800817
@@ -859,32 +876,36 @@ static public function saveFileFromURL($url = null, $destination)
859876 * Read PDF TO Browser
860877 *
861878 * @param string|null $path
862- * - [full path to file ]
879+ * - [base path will be automatically added ]
863880 *
864881 * @return void
865882 */
866883 static public function readPDFToBrowser ($ path = null )
867884 {
868- if (!empty ($ path ) && self ::exists ($ path )){
885+ $ fullPath = self ::getBasePath ($ path );
886+
887+ if (self ::exists ($ fullPath )){
869888 @header ("Content-type: application/pdf " );
870- @header ("Content-Length: " . filesize ($ path ));
871- readfile ($ path );
889+ @header ("Content-Length: " . filesize ($ fullPath ));
890+ readfile ($ fullPath );
872891 }
873892 }
874893
875894 /**
876895 * Convert image to base64
877896 *
878897 * @param string|null $path
879- * - [full path to file ]
898+ * - [base path will be automatically added ]
880899 *
881900 * @return null|string
882901 */
883902 static public function imageToBase64 ($ path = null )
884903 {
885- if (!empty ($ path ) && self ::exists ($ path )){
886- $ type = pathinfo ($ path , PATHINFO_EXTENSION );
887- $ data = file_get_contents ($ path );
904+ $ fullPath = self ::getBasePath ($ path );
905+
906+ if (self ::exists ($ fullPath )){
907+ $ type = pathinfo ($ fullPath , PATHINFO_EXTENSION );
908+ $ data = file_get_contents ($ fullPath );
888909
889910 return 'data:image/ ' . $ type . ';base64, ' . base64_encode ($ data );
890911 }
@@ -1169,19 +1190,6 @@ static public function paymentIcon($payment = null)
11691190 return $ dataSet [$ payment ] ?? $ dataSet ['cc ' ];
11701191 }
11711192
1172- /**
1173- * File exist and not a directory
1174- *
1175- * @param string|null $path
1176- * - [full path to file]
1177- *
1178- * @return bool
1179- */
1180- static public function exists ($ path = null )
1181- {
1182- return !is_dir ($ path ) && file_exists ($ path );
1183- }
1184-
11851193 /**
11861194 * Replace and recreate path to
11871195 * - (/) slash
@@ -1192,7 +1200,11 @@ static public function exists($path = null)
11921200 */
11931201 static public function stringReplacer ($ path = null )
11941202 {
1195- return Server::cleanServerPath ($ path );
1203+ return str_replace (
1204+ ['\\' , '/ ' ],
1205+ DIRECTORY_SEPARATOR ,
1206+ trim ((string ) $ path )
1207+ );
11961208 }
11971209
11981210}
0 commit comments