I have a webcam set up to dump images onto an FTP server.
I'm hosting a website on a different server, and I want that website to display a selected image that is uploaded by the camera.
I'm trying to use file_exists() to check that the image is actually there, but it just times out when trying to do its business on the remote server.
My script looks like:
while (false == $valid_image)
{
$webcam_file = 'http://www.site.com/clients/1521/webcam/1521_webcam_' . gmdate('Ymd', $today - ($i * 86400)) . '.jpg';
// check if file exists, and if it's a valid jpeg
if (file_exists($webcam_file) && getimagesize($webcam_file))
{
//code to display image
$valid_image = true;
}
$i++;
}
This works great if the source is a local file, but doesn't work if reading the file from a different server than the script resides on. Is there a different (and correct) way of doing this, or something I need to enable to be able to do this?
Actually, in a perfect world, I would run the below function with the source file being a file on the FTP upload server, and the destination being the local server. I would feed this function a specific remote file (after checking that it exists), and the function would save the resized & rotated result on the same local server that the website lives on. This will avoid issues should the FTP upload server happen to be down - the image will already be on the destination server.
But I think I'm facing the same problem - inability to "open" a file from a remote server - even though I can read/display it in a browser of course. Seems that displaying is different from reading.
function RotateResize($source_file, $degrees, $max_width, $max_height, $dest_file, $quality)
{
$src = ImageCreateFromJpeg($source_file);
$rotated_image = imagerotate($src, $degrees, 0);
$size = GetImageSize($source_file);
$width = $size[1]; // swapped, since image is rotated
$height = $size[0]; // swapped, since image is rotated
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
if (($width <= $max_width) && ($height <= $max_height))
{
$tn_width = $width;
$tn_height = $height;
}
elseif (($x_ratio * $height) < $max_height)
{
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else
{
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
$dst = imagecreatetruecolor($tn_width,$tn_height);
imagecopyresampled($dst, $rotated_image, 0, 0, 0, 0, $tn_width,$tn_height,$width,$height);
ImageInterlace($dst, 1);
if (ImageJpeg($dst, $dest_file, $quality))
{
ImageDestroy($src);
ImageDestroy($rotated_image);
ImageDestroy($dst);
return true;
}
else
{
return false;
}
}
Any insights about this, or suggestion of how to "get at" a remotely located image file?