Friday 22 December 2017

json - PHP try...catch failing to "catch"

I have the following code that to which the file is an
ajax call:



try {
echo
json_encode(exif_read_data($_POST["url"]));
} catch (Exception $e)
{
echo "Invalid
URL";
}


Its
purpose is to accept an image url and return the JSON-encoded EXIF data, and when there
is a "correct" url, the
json_encode(exif_read_data($_POST["url"])); works just
fine.




However, when I intentionally
pass it a "bad" url in the jQuery ajax call
"url" : "url1", or in the php file directly
..exif_read_data("bob"), I receive this error in my console
log:



Warning: exif_read_data()
[function.exif-read-data]: Unable to open file in ../public_html/_photos/ajax/exif.php
on line 3
false

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...