Current location: Hot Scripts Forums » Programming Languages » PHP » Scanning Directory


Scanning Directory

Reply
  #1 (permalink)  
Old 08-07-06, 10:18 AM
dodotopia dodotopia is offline
Newbie Coder
 
Join Date: Apr 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Scanning Directory

What PHP command would I invoke to scan a directory?

I'm trying to send a video clip from my phone to my webserver, have some php recognize a new file so it can build a new page (i.e. for today's videos) and display it automatically.

Any insight on how I might do that?

I can code the PHP but just need some direction...anybody have experience on sending picture/videos to an email address and have it auto-save the attachment to a directory?

Thanks...
Reply With Quote
  #2 (permalink)  
Old 08-07-06, 01:56 PM
Patiek Patiek is offline
Wannabe Coder
 
Join Date: Nov 2003
Posts: 165
Thanks: 0
Thanked 0 Times in 0 Posts
You need to look into email piping and using PHP stdin, etc. I am sure looking for "email piping php" in google will turn up some results. Essentially you will be piping email that comes in on an email address, name@example.com, to a PHP script that accepts input via stdin (again, just search google... I am sure there are many examples available). Thus, you will need to both configure the email address to pipe to the PHP script and create the PHP script that will be able to handle the email data. Enabling email piping can vary, so just ask your host for help in that matter.

As for checking directory contents:
PHP Code:

$handle opendir("folder/");

while (
false !== ($file readdir($handle)))
{
    echo 
$file "\n";
}
closedir($handle); 
Take a look at readdir() function.

Last edited by Patiek; 08-07-06 at 02:03 PM.
Reply With Quote
  #3 (permalink)  
Old 08-10-06, 02:58 AM
ThaLyric ThaLyric is offline
Newbie Coder
 
Join Date: Jul 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
I've created s script for something like that :

PHP Code:

<?php

    
/*
        Fransjo Leihitu
        http://www.leihitu.nl
        
        USAGE:
        
        
        // LIST ALL
        if($myDirList=get_dirlist("/mypath/"))
        {
            print "<pre>";
            print_r($myDirList);
            print "</pre>";
        }
        
        // LIST ONLY GIF AND JPG
        $ext=array();
        $ext[]="gif";
        $ext[]="jpg";
        
        if($myDirList1=get_dirlist("/mypath/",$ext))
        {
            print "<pre>";
            print_r($myDirList1);
            print "</pre>";
        }        
    */


    
function getFileExtension($filename="")
    {
        if(isSet(
$filename))
        {
            
$filename=trim(strip_tags(stripslashes($filename)));
            if(
$filename!="")
            {
                
$dummyArray=split("[/.]",$filename);
                
$count=count($dummyArray);
                if(
$count>0)
                {
                    return 
strtolower($dummyArray[$count-1]);
                }
            }
        }
        
        return 
false;
    }
    
    function 
get_dirlist($dir,$extension=null)
    {
        
$dirlist=array();

        if(
is_dir($dir))
        {
            if (
opendir($dir))
            {
                
// open the dir
                
$dh=opendir($dir);
                
                
// get all the files in the dir
                
while ($filename=readdir($dh))
                {
                    
// is the item NOT a dir
                    
if (!is_dir($filename))
                    {
                        
// look for an extension?
                        
if($extension!=null)
                        {
                            
// get the file extension
                            
$fileExtension=trim(getFileExtension($filename));
                            
                            
// check it he file extension is in the array
                            
if(in_array($fileExtension$extension)
                            {
                                
// add the filename to the list
                                
$dirlist[]=$filename;
                            }                            
                        } else {
                            
// just add the filename to the list
                            
$dirlist[]=$filename;
                        }
                    }
                }
                
closedir($dh);
                
                
// sort the list by name
                
asort($dirlist);
                
                
//return the list
                
return $dirlist;                
            }
        }
        
        
// hmm something wrong happend, return false
        
return false;
    }

?>

Last edited by ThaLyric; 08-10-06 at 03:01 AM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Directory acces control scripts CraigTurgeon PHP 0 01-24-06 06:36 PM
help needed: Comparing two directory tree structures Raj_thota Script Requests 0 10-27-05 12:17 AM
Link exchange with web directory lovely Traffic Exchange 0 10-18-05 10:40 AM
Add URL to human edited Directory 24-7 Shopping Directory Traffic Exchange 1 08-25-04 07:27 PM
Need Epinions-lite system in PHP & MYSQL wali001 Job Offers & Assistance 4 01-12-04 06:02 AM


All times are GMT -5. The time now is 07:23 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.