SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    whther the file name is exist or not?

    Hello,

    I want to check exact filename while uploading the file. because i have diffent table for each and every file so before inserting i want to check the file name is proper or not.

    so if my file name is like this
    $a ='c:/Program Files/../../../../files/ipc_details.csv';
    then i want to check ipc_details.csv file every time so user can not dump wrong file(say abc.csv) into it.

    May be i have to use preg_match here. but how can we check only last part of file path that is ipc_details.csv?

    please tell me.

    Thnaks in advance

  2. #2
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $userfile_name $_FILES['ufile']['name'];

         if(
    preg_match("/ipc_details.csv/i"$userfile_name))
         { 
    Tried this, working fine. is this the good way to check it or i can do it with different way?

  3. #3
    SitePoint Addict
    Join Date
    Oct 2008
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't know whats the best way but you could do it like this also..
    PHP Code:
    if (strtolower($user_file) === 'ipc_details.csv'

  4. #4
    SitePoint Evangelist
    Join Date
    Jun 2006
    Location
    Wigan, Lancashire. UK
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $fileName = pathinfo($fullFileName,PATHINFO_BASENAME);
    ---
    Development Projects:
    PHPExcel
    PHPPowerPoint

  5. #5
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if (basename($a) == 'ipc_details.csv'
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  6. #6
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    rajug,

    Great information. thank you!

    thanks to all of you.


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
  •