Reformat whitespace
This commit is contained in:
		
							parent
							
								
									fbd10d6b11
								
							
						
					
					
						commit
						39928a2c56
					
				
							
								
								
									
										68
									
								
								php/get.php
									
									
									
									
									
								
							
							
						
						
									
										68
									
								
								php/get.php
									
									
									
									
									
								
							| @ -6,47 +6,47 @@ define("IMG_URL", "img/"); | |||||||
| main(); | main(); | ||||||
| 
 | 
 | ||||||
| function main(): void { | function main(): void { | ||||||
|   $data = json_decode(file_get_contents('php://input'), true); | 	$data = json_decode(file_get_contents('php://input'), true); | ||||||
|   $array = []; | 	$array = []; | ||||||
| 
 | 
 | ||||||
|   $category = $data["category"]; | 	$category = $data["category"]; | ||||||
|   $directory = IMG_DIR.$category; | 	$directory = IMG_DIR.$category; | ||||||
|   if (!is_dir($directory)) return; | 	if (!is_dir($directory)) return; | ||||||
|   foreach (scandir($directory) as $file) { | 	foreach (scandir($directory) as $file) { | ||||||
|     if ($file === ".") continue; | 		if ($file === ".") continue; | ||||||
|     if ($category === "" && $file === "..") continue; | 		if ($category === "" && $file === "..") continue; | ||||||
| 
 | 
 | ||||||
|     if ($category != "") $file = $category.'/'.$file; | 		if ($category != "") $file = $category.'/'.$file; | ||||||
|     $is_dir = is_dir(IMG_DIR.$file); | 		$is_dir = is_dir(IMG_DIR.$file); | ||||||
|     if (!$is_dir && !is_valid_file_type($file)) continue; | 		if (!$is_dir && !is_valid_file_type($file)) continue; | ||||||
| 
 | 
 | ||||||
|     $file_item = []; | 		$file_item = []; | ||||||
|     $file_item["is_dir"] = $is_dir; | 		$file_item["is_dir"] = $is_dir; | ||||||
|     $file_item["url"] = ROOT_URL.IMG_URL.$file; | 		$file_item["url"] = ROOT_URL.IMG_URL.$file; | ||||||
|     array_push($array, $file_item); | 		array_push($array, $file_item); | ||||||
|   } | 	} | ||||||
|   echo json_encode($array); | 	echo json_encode($array); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function is_valid_file_type(string $filename): bool { | function is_valid_file_type(string $filename): bool { | ||||||
|   $file_extensions = [ | 	$file_extensions = [ | ||||||
|     // Image extensions
 | 		// Image extensions
 | ||||||
|     'jpg', | 		'jpg', | ||||||
|     'jpeg', | 		'jpeg', | ||||||
|     'png', | 		'png', | ||||||
|     'gif', | 		'gif', | ||||||
|     'tiff', | 		'tiff', | ||||||
|     'bmp', | 		'bmp', | ||||||
|     'webp', | 		'webp', | ||||||
|     'svg', | 		'svg', | ||||||
|     // Video extensions
 | 		// Video extensions
 | ||||||
|     'mp4', | 		'mp4', | ||||||
|   ]; | 	]; | ||||||
| 
 | 
 | ||||||
|   foreach ($file_extensions as $file_extension) { | 	foreach ($file_extensions as $file_extension) { | ||||||
|     if (str_ends_with($filename, $file_extension)) return true; | 		if (str_ends_with($filename, $file_extension)) return true; | ||||||
|   } | 	} | ||||||
|   return false; | 	return false; | ||||||
| } | } | ||||||
| ?>
 | ?>
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user