我有这个 php 脚本,它应该通过 HTTP 加载 mjpg 流并通过 HTTPS 输出。然而,它产生的只是一个破碎的图像:
<?php
function proxyMjpegStream($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_BUFFERSIZE, 8192);
header("Content-Type: multipart/x-mixed-replace; boundary=myboundary");
curl_exec($ch);
curl_close($ch);
}
// Get the URL of the MJPEG stream to proxy
if (isset($_GET['url'])) {
$mjpegUrl = $_GET['url'];
// Validate that the URL is a valid HTTP source
if (filter_var($mjpegUrl, FILTER_VALIDATE_URL) && strpos($mjpegUrl, 'http://') === 0) {
proxyMjpegStream($mjpegUrl);
exit;
}
}
// Invalid or missing MJPEG URL parameter
header("HTTP/1.0 400 Bad Request");
echo "Invalid MJPEG URL";
?> Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号