PHP check if file exists on my server, based on a full URL

Posted by stef on Stack Overflow See other posts from Stack Overflow or by stef
Published on 2010-03-16T20:41:53Z Indexed on 2010/03/16 23:11 UTC
Read the original article Hit count: 342

Filed under:

I have an app that generates invoices in the form of PDF files stored in a directory on my server. Before mailing out this invoices I'd like to make sure that the URL (not server path) which I store in my DB does indeed point to a valid PDF file.

Something could have gone wrong that wrote a value to that field in the db, but for example the filename is missing; meaning the file is not in the specified directory.

AFAIK file_exists just checks server paths but not URL's.

I could always store the server path too, or assemble it, but I'm wondering if i can do this check based on a full http url ending with a filename?

EDIT: yeah CURL occurred to me too but doesn't that seem a bit heavy for such a simple task? Perhaps I should just store the server path too.

© Stack Overflow or respective owner

Related posts about php