AndyB
Well-known member
I would like to be able to use cURL and have the script determine if the file path is reachable. Here's an example of code that verifies the domain is reachable:
This works fine. But if I change the path to something like this:
http://www.google.com/path_to_invalid_image.jpg
it still shows as a valid path.
So how would I modify the code to show an error if the path to a file is invalid?
PHP:
<?php
// Create a curl handle to a non-existing location
$ch = curl_init('http://www.google.com/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if (curl_exec($ch) === false) {
echo 'Curl error: ' . curl_error($ch);
}
else
{
echo 'Operation completed without any errors';
}
// Close handle
curl_close($ch);
?>
This works fine. But if I change the path to something like this:
http://www.google.com/path_to_invalid_image.jpg
it still shows as a valid path.
So how would I modify the code to show an error if the path to a file is invalid?
Last edited: