Jump to content

Quick solve


LiamProductions

Recommended Posts

Hey.

I've made a script to get all the .php extension files in the directory and make a link to them.

Now. I was wondering how do i make it so that i can make it so the filetype comes at the end like PHP or .php

 

I have tried filetype($filename) but it says file :s

 

Heres code:

<?php
error_reporting(E_ALL);
foreach(glob("*.php") as $filename) {
echo "<center>";
  echo "<table border=\"0\ cellspacing=\"50\"><tr><td><a href=\"$filename\">$filename</a></td><td> " . filesize($filename) . "KB</td><td>" . filetype($filename) . "</td></tr></table>";
  }
  echo "</center>";
  
?>

Link to comment
https://forums.phpfreaks.com/topic/64508-quick-solve/
Share on other sites

Well you could try

 

$ext = substr($filename, strrpos($filename, '.')+1);

// if $filename == 'test.php'  :  $ext = "php"
// if $filename == 'myscript.inc'  :  $test = "inc"

 

If you want to include the period before the extension, remove the +1 at the end in the code above -- then just use $ext and place it where you need it.

 

OR

 

you could simply hardcode it into your code:

 

<?php
error_reporting(E_ALL);
foreach(glob("*.php") as $filename) {
echo "<center>";
  echo "<table border=\"0\ cellspacing=\"50\"><tr><td><a href=\"$filename\">{$filename}.php</a></td><td> " . filesize($filename) . "KB</td><td>" . filetype($filename) . ".php</td></tr></table>";
  }
  echo "</center>";
  
?>

Link to comment
https://forums.phpfreaks.com/topic/64508-quick-solve/#findComment-321545
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.