Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



How to check if file exists in directory with Php

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 03-11-2009
Member
 
Join Date: Apr 2009
Posts: 87
How to check if file exists in directory with Php
  

Does any one know the program how to Check If File Exists In A Directory With Php. What is the code and what are syntax need to be used while searching file? Any recommendations and suggestions are appreciated.

Reply With Quote
  #2  
Old 03-11-2009
Member
 
Join Date: May 2008
Posts: 2,291
Re: How to check if file exists in directory with Php

Try this program in php to check if file exists :
Code:
<?PHP
 
$filename = 'file.csv'; 
IF (FILE_EXISTS($flnm)) 
{
PRINT "The file $flnm exists";
} 
ELSE 
{
PRINT "The file $flnm does not exist";
}
 
?>
Reply With Quote
  #3  
Old 03-11-2009
Member
 
Join Date: Jan 2009
Posts: 199
Re: How to check if file exists in directory with Php

Code:
bool file_exists ( string $filename )
This Checks whether a file or directory exists or not. On windows, use //computername/share/filename or \\computername\share\filename to check files on network shares.I'm thinking the quickest solution for this is to use the fopen() function... The file_exists() function doesn't support remote URL's, however, fopen() does.file() - Reads entire file into an array, is_writable() - Tells whether the filename is writable.
Reply With Quote
  #4  
Old 03-11-2009
Member
 
Join Date: Dec 2008
Posts: 177
Re: How to check if file exists in directory with Php

Code:
function file_nm($pth, $fme){
    if ($pos = strrpos($fme, '.')) {
           $nm = substr($fme, 0, $ps);
           $ext = substr($fme, $ps);
    } else {
           $nm = $fme;
    }
 
    $nwpth = $pth.'/'.$fme;
    $nwme = $fme;
    $count = 0;
    while (file_exists($nwpth)) {
           $nwname = $name .'_'. $count . $ext;
           $nwpth = $pth.'/'.$nwname;
           $count++;
     }
 
    return $nwme;
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to check if file exists in directory with Php"
Thread Thread Starter Forum Replies Last Post
Unix: Check if a file exists with certain prefix Gracious Software Development 4 29-05-2010 06:01 PM
Batch file to check directory Trini Alvarado Software Development 5 01-04-2010 11:00 AM
Powershell: To check a directory exists or not? Chandrakant81 Software Development 3 18-02-2009 05:26 PM
C++ code to check or search if a file exists or not? RadhaV Software Development 4 17-02-2009 10:33 PM
How to Check File Exists or Not in Linux Ettan Software Development 0 19-12-2008 12:42 PM


All times are GMT +5.5. The time now is 02:26 AM.