WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 Resources
Web Development Content
Internet Security Software
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
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

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
bastien koert
Date : Oct 26th 2005
Grade : 2 of 5 (graded 3 times)
Viewed : 10911
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  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
A simple php file uploader
Categories : PHP, Filesystem, HTML and PHP
File Explorer, browse, upload, download and edit your web site files with only a browser and a HTTP connection.
Categories : Complete Programs, Content Management, Filesystem, PHP
ezRemoteScripter - A little remote scripting (AJAX) helper
Categories : PHP, Java Script, AJAX
This script will read all images from a folder and read the files into an array. It uses rand() to get a random number. It will display a random image from the image folder given.
Categories : PHP, Arrays, Graphics, Filesystem
Checking to see if a file exists with PHP
Categories : PHP, Filesystem, Perl
Contents Page - a script to build contents pages.
Categories : Complete Programs, PHP, Utilities, Filesystem
Function that allows a Javascript cookie to be set after HTML has been outputted to the page.
Categories : PHP, Java Script, Cookies, HTML and PHP
Functions to read a template file and fill in PHP variables. It will also fill in array variables, displaying parts of the template multiple times.
Categories : PHP, Variables, Filesystem
Open directory and File download
Categories : PHP, Filesystem, Directories, HTML and PHP
Compare two texts and display a block of text with the differences between them.
Categories : PHP, PHP Classes, Filesystem, Strings, Arrays
3 lines of Code to extract Tar, Zip, Gzip etc..
Categories : PHP, Filesystem, PHP Classes, Compression
How to let a user download a picture by clicking on it instead of needing to right click and Save-As.
Categories : HTTP, PHP, HTML and PHP, Filesystem