WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : filesystem Show Files Script
Categories : PHP, Filesystem, Java Script Click here to Update Your Picture
bastien koert
Date : Oct 26th 2005
Grade : 2 of 5 (graded 3 times)
Viewed : 9225
File : No file for this code example.
Images : No Images for this code example.
Search : More code by bastien koert
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

I have a bunch of videos of various formats and images that I show on a web page. To make things easy on myself I wrote this to scan the folder where the videos sit and to display them in a way that makes sense. So this script reads the file list into an array and then sorts it by time (based on weeks in the year). Then I show the links arranged by folders for each week of the year. That folder is link and when clicked it shows/hides the videos for that week.

Enjoy

Bastien

<html>
<title>Bastien's Video List</title>
<head>
<script language='javascript'>
function show_list(d)
{
  var sInline = 'inline';
  if (document.getElementById(d).style.display == 'inline'){ sInline='none'; }
  document.getElementById(d).style.display = sInline;
}//end func
</script>
</head>
<body>

<?php
//preview video scripts
//read in the dir files and display them as links
//onclicking the link reloads the page with the video
//organize the vids by date...

if(isset($_GET['v']))
{
 
show_video();
}else{
 
show_list2();
}
//endif
?>

</body>
</html>

<?php
function show_video()
{
 
$file = '';
 
$type = '';
 
 
$file = @$_GET['v'];
 
$type = stristr($file,".");

 
//check for file
 
if (!file_exists("./vids/$file"))
  {
   
//file doesn't exist
   
confirm("File can't be found. Please try choosing it again from the list.");
   
show_list();
    die();
  }
//end if 
 
echo "<center>";
 
 
//check file type
 
if (($type == ".mov")||($type == ".qt")||($type == ".mp4"))
  {
   
//if quicktime (.mov, .qt)
?>
   
      <object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="256" width="320">
        <param name="src" value="<?php echo "./vids/$file" ?>">
        <param name="autoplay" value="true">
        <param name="controller" value="true">
        <embed height="256" width="320" src="<?php echo "./vids/$file" ?>" pluginspage="http://www.apple.com/quicktime/download/" type="video/quicktime" controller="true" autoplay="true">
      </object>
<?php
 
 
}elseif (($type == ".wmv")||($type == ".mpeg")||($type == ".avi")||($type == ".wav")){

 
//if windows (.wmv,.mpeg,.avi,.wav)
?>
    <OBJECT ID="Player" CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95">
      <PARAM name="autoStart" value="True">
      <PARAM name="fileName" value="<?php echo "./vids/$file" ?>">
    </OBJECT>
<?php
 
}elseif($type == ".gif" || $type ==".jpeg" || $type == ".jpg")
  {
    echo
"<img src='./vids/$file'>";
 
  }
//end if

 
echo "<br><br><br><a href='vids.php'>Back to list</a></center>";

}
//end function



function show_list2()
{
 
//organize vids by data
  //read into array
  //sort array
  //show folders in collapsed tables
  //onclick folder/date to 'show folder contents'

 
echo "<center><h2>I take no responsibility if you ARE OFFENDED by these videos.<br /> YOU CHOOSE TO CLICK THE LINK!</h2></center>";
  echo
"<table width=75% cellpadding=5 cellspacing=0 align=center><tr valign=top><td>";
   
 
$dir   = './vids/';
 
$aVids = array();

 
//get data into array
  //open the main video dir
 
if ($handle = opendir($dir))
  {
   
//loop thru the files in the dir
   
while (false !== ($file = readdir($handle)))
    {
     
//check to make sure the file is not a directory
     
if ($file != "." && $file != "..")
      {
       
//reset the new var to empty string
       
$new = '';
       
//clear the stats cache of file data
       
clearstatcache();
             
//get the file name and find out if its a new file
             
if (file_exists($dir.$file))
              {
               
//check to see if the video is 'new' and needs the new tag
               
if ((time() - filemtime($dir.$file)) < 345600)
                {   
           
$new = "\n\t\t <span style=\"font-weight:bold; color:red; font-size:smaller;\">New!</span>";
          } 
         
//add the video to the array
         
$aVids[] = array('file'=>$file, 'dtime'=>filemtime($dir.$file), 'week'=>date("W",filemtime($dir.$file)), 'new'=> $new);
        }
//end if
     
}//end if
   
}//loop
 
}//end if

        // Turn array into a list of columns
       
foreach ($aVids as $key => $row) {
           
$file[$key]    = $row['file'];
           
$week[$key]    = $row['week'];
           
$new[$key]     = $row['new'];
        } 

 
//  sort the arays
 
array_multisort($week,SORT_DESC,$aVids);

 
$old_week = 0;
 
$display  = 10;
 
$nCount   = 0;
 
//start table
 
//  echo "<table border=1>\n<tr valign='top'><td>\n";
 
 
for($x=0; $x < count($aVids); $x++)
  {
    if ((
$old_week != $aVids[$x]['week']) && ($old_week != 0))
    {
     
//close previous table
     
echo "\n\t</table></div>\n";
     
     
//multiple columns
     
$nCount++;
      if (
$nCount % $display == 0 )
      {
        echo
"</td><td>";
      }
      echo
"\n<img src='folder.gif' /><a href='#' onclick='show_list(" . $aVids[$x]['week'] . ");'> Week " . $aVids[$x]['week'] . "</a><br />\n";
     
     
//start new hidden span
     
echo "\n\t<div id='" . $aVids[$x]['week'] . "' style='display:none;'>\n\t<table border=1>";
     
     
$old_week = $aVids[$x]['week'];
     
   
    }elseif (
$old_week == 0){
     
     
//first run thru
     
echo "\n<img src='folder.gif' /><a href='#' onclick='show_list(" . $aVids[$x]['week'] . ");'> Week " . $aVids[$x]['week'] . "</a><br />\n";
     
     
//start new hidden span
     
echo "\n\t<div id='" . $aVids[$x]['week'] . "' style='display:none;'>\n\t<table border=1>";
     
     
$old_week = $aVids[$x]['week'];
    }
   
   
//show the individual elements
   
echo "\n\t\t<tr><td>      <a href='" . $_SERVER['PHP_SELF'] . "?v=". $aVids[$x]['file'] . "'>". $aVids[$x]['file'] ."</a>";
    if (
$aVids[$x]['new']!=''){ echo  "(" .$aVids[$x]['new']. ")</td></tr>"; }
   
   
  }
//next 
 
echo "\n</td></tr></table>";
}       
?>



A simple configuration file editor to ease you life in setting up php applications. Reads variables from a given file automatically and displays current value. New value will be written to file after submit.
Categories : PHP, Filesystem, Regexps, Java Script
The toll booth
Categories : PHP, Java Script, Filesystem
Complete NotePad application for Websites (Like Yahoo Notepad)
Categories : PHP, Web Applications, Filesystem, Java Script, Complete Programs
Classic guest book made with PHP and Flash
Categories : PHP, Flash, Java Script
Upload any fixed type of files, control file type through javascript and encrypt filename using php so file not get overwrite
Categories : PHP, Java Script, Functions, PHP References, Form Processing
Menu in sliding bar or tree style. Handles frames by using small amount of javascript. Handles external and internal pages. Allows custom code to replace a menu item.
Categories : PHP Classes, PHP, Java Script, DHTML
An efficient iterative and buffered text file reader
Categories : PHP, Classes and Objects, Filesystem, PHP Classes, Log Files
Using php3 to upload files, uploading files, file uploads.
Categories : PHP, Filesystem, HTTP
file class , uploade file , download file already uploaded on another website
Categories : PHP, PHP Classes, Filesystem, Web Services
PHP Calendar
Categories : PHP, Calendar, Date Time, Java Script, CSS
Remote File Saving with PHP - Download and serve a remote file. The content of the file will be updated at fixed intervals.
Categories : PHP, Filesystem, Cache, Sockets, HTTP
Convert a File database into MySQL
Categories : PHP, Filesystem, Databases, MySQL, Beginner Guides
How to ifconfig down/up a list of IP's
Categories : Arrays, Strings, Filesystem, PHP
Finds files on your site, uses UNIX find command.
Categories : Complete Programs, Filesystem, PHP
A flat file counter
Categories : PHP, Cookies, Filesystem, Beginner Guides