Results 1 to 4 of 4

Thread: How to check if file exists in directory with Php

  1. #1
    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.

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    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";
    }
     
    ?>

  3. #3
    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.

  4. #4
    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;

Similar Threads

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,939,572.78885 seconds with 17 queries