tags:

views:

58

answers:

2

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.

A: 

You could validate the request by opening the URL using PHP+cURL as described here and check the HTTP status code that's returned.

inkedmn
A: 

Hi,
You can use function file_get_contents() or fopen()

B7ackAnge7z