Learn PHP on Repl.it: Displaying File Names and Sizes


53

Repl.it which is an online text editor service that has a compiler that supports several programming languages ​​so that you can learn in practice to create applications or programs anywhere and anytime for free. Repl.it also provides a custom domain feature for those of you who want to build a website that is a landing page, you can use this feature to make your website unique.

In this article, we will learn the practice of displaying website-based file names and sizes in your Repi.it project using the PHP programming language. After giving the tutorial, you are expected to be able to develop a simple program into your website.

STEPS

1. Visit the site Repl.it.

2. Click Log In.

3. Enter the username and password, press Enter. Or use an Oauth System like Google, Github. Wait until the Repl.it member dashboard appears.

4. Click New Repl to create a new project for the PHP programming language in Repl.it.

5. Choose the PHP Web Server programming language and enter the project name without giving any spaces, press Create repl.

6. Delete all command codes in the text editor.

7. Type the command code to display the name along with the files in the directory or project.

<html>
<head>
<title>Menampilkan File di dalam Direktori</title>
</head>
<body>
<?php
//Menampilkan file untuk semua file ekstensi
$fileList = glob('*');
foreach($fileList as $filename){
if(is_file($filename)){
echo $filename, '<br>'; 
//MENAMPILKAN UKURAN FILE DALAM SATUAN MEGABYTE
echo round((filesize($filename)) / 1024 / 1024, 3) ." MB.<br>";
} 
}
?>
<br />
<br />
<?php
//Menampilkan file untuk satu file ekstensi
$fileList2 = glob('*.pdf');
foreach($fileList2 as $filename2){
if(is_file($filename2)){
echo $filename2, '<br>';
//MENAMPILKAN UKURAN FILE DALAM SATUAN MEGABYTE
echo round((filesize($filename2)) / 1024 / 1024, 3) ." MB.<br>"; 
} 
}
?>
</body>
</html>

DESCRIPTION

$fileList = glob('*');

The command code above serves to accommodate all file name data into an array in the storage by enforcing all file extensions.

$fileList = glob('*.pdf');

The command code above serves to accommodate all file name data into an array in the storage by applying only one file extension.

round((filesize($filename2)) / 1024 / 1024, 3)

The command code above serves to calculate the result of the file size in MegaByte (MB) by giving 3 digits behind the comma contained in the file that has been selected in filesize().

8. Click Run.

9. Click the new tab icon.

10. Here are the results.

In the image above, you can see the names and file sizes printed in the browser for some of the files in the directory. There is also a separator between the display name and the overall file size or selecting only one file extension.

Finished.

CLOSING

You can create an application or program to display the name and/or size of a website-based file in a directory without using a database at all with the PHP programming language implemented in Repl.it. This is suitable for those of you who want to create programs or applications that share a file or folder so that visitors can access the website.

READ OTHER ARTICLES

Leave a comment

Your email address will not be published.