Hiding an image URL...
Go to solution
Solved by colonel_mortis,
A simple solution would be to have another PHP file on your server that proxies the image. That script would look something like
<?php $webcamImageUrl = "http://111.111.111.111/snapshot.jpeg"; $curlRequest = curl_init(); curl_setopt($curlRequest, CURLOPT_URL, $webcamImageUrl); curl_setopt($curlRequest, CURLOPT_HEADER, false); // Don't include the response headers in the result curl_setopt($curlRequest, CURLOPT_RETURNTRANSFER, true); // Return the body of the requested resource curl_setopt($curlRequest, CURLOPT_TIMEOUT, 10); // Timeout if it takes > 10s $imageData = curl_exec($curlRequest); if (curl_error($curlRequest)) { http_response_code(500); echo "Error: " . curl_error($curlRequest); exit; } header("Content-Type: " . curl_getinfo($curlRequest, CURLINFO_CONTENT_TYPE)); echo $imageData;
That could be improved by caching the image on disk so it doesn't get requested too often.
PHP isn't the ideal language for this because it has to load the whole image into memory before it can send it back to the user, but it should be good enough for your use case.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now