+ Reply to Thread
Results 1 to 3 of 3

Thread: php - read filename extension in database

  1. #1
    Dotwebs's Avatar
    Dotwebs is offline Wannabe Geek Dotwebs will become famous soon enough
    Join Date
    Jul 2008
    Location
    Dublin (Sort of)
    Posts
    102

    Default php - read filename extension in database

    Hi,

    I wonder if anyone can help me with this. I have a recordset to get the names of files to download, these are mostly PDFs so I have added the code to output a PDF file. If the file is not pdf I want to output it in the correct format.

    So
    PHP Code:
    if (file is pdf) {
    // We'll be outputting a PDF 
    header('Content-type: application/pdf'); 
    // called download.pdf 
    header('Content-Disposition: inline; filename="download.pdf"'); 
    // The source of the PDF
    readfile("../pathtofile/".$row_rsFilelist['filename']); 
     
    } else {
    //we'll output probably just a link

    any help would be appreciated.

    Thanks
    The cure for boredom is curiosity. There is no cure for curiosity - Dorothy Parker

  2. #2
    louie's Avatar
    louie is offline Senior Member louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough louie will become famous soon enough
    Join Date
    Jan 2006
    Location
    Dublin, Ireland
    Posts
    2,328

    Default

    You can use filetype function available in php

    PHP: filetype - Manual

    or you can check for the ".pdf" using stristr

    PHP: stristr - Manual
    :. Web Design & Development Web Design Ireland
    :. Search Engines Optimization Search Engines Optimization
    :. Car Parts & Accessories Car Parts
    :. Cars Ireland Cars Ireland
    :. I Have 2 Find It Directory SEF Directory

  3. #3
    Dotwebs's Avatar
    Dotwebs is offline Wannabe Geek Dotwebs will become famous soon enough
    Join Date
    Jul 2008
    Location
    Dublin (Sort of)
    Posts
    102

    Default

    Thanks Louie, I found a solution that works - here it is in case anyone else needs it:

    if(strtolower(substr($row_rsFilelist['filename'], strlen($row_rsFilelist['filename'])-3)) == 'pdf'))

    The cure for boredom is curiosity. There is no cure for curiosity - Dorothy Parker

+ Reply to Thread

Similar Threads

  1. Harry Potter - Will you read it?
    By blacknight in forum Off topic discussion
    Replies: 2
    Last Post: 24-10-2009, 01:34 AM
  2. Read before posting domains for sale
    By blacknight in forum Domains For Sale
    Replies: 2
    Last Post: 11-04-2008, 02:53 PM
  3. Do you read AUP / TOS before signing up?
    By blacknight in forum Hosting
    Replies: 14
    Last Post: 05-02-2008, 04:21 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Optimization by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64