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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.