Hi guys, I have a script that gabs a static JPEG picture from a webcam and then SCP's the file up to a web server. The script is very slow and eats system resources (90%+).
Is there a way to do this without saving the file locally? i.e. store it in memory before uploading it via FTP?
<?php
$url = 'http://admin:password@webcamIP/img/picture.cgi?';
$img = 'webcam.jpg';
file_put_contents($img, file_get_contents($url));
error_reporting(E_ALL);
ini_set('display_errors', 1);
$ch = curl_init();
$localfile = 'webcam.jpg';
$fp = fopen($localfile, 'r');
curl_setopt($ch, CURLOPT_URL, 'sftp://admin:password@somehost.1/somepath/'.$localfile);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
curl_exec ($ch);
$error_no = curl_errno($ch);
curl_close ($ch);
if ($error_no == 0) {
$error = 'File uploaded succesfully.';
} else {
$error = 'File upload error.';
}
echo $error.' '.$error_no;
?>