Search the Community
Showing results for tags 'jpeg'.
-
Hi. I have a problem where when i try to display the uploaded JPEG file, the browser would only dispay the placeholder for an image . I think the problem is within the 3rd IF statement. Please help me thanks. <?php if($_SERVER['REQUEST_METHOD'] == 'POST') { if(isset($_FILES['photo']) && is_uploaded_file($_FILES['photo']['tmp_name']) && $_FILES['photo']['error']==UPLOAD_ERR_OK) { if($_FILES['photo']['type']=='image/jpeg') { echo 'asdsad'; $tmp_img = $_FILES['photo']['tmp_name']; $image = imagecreatefromjpeg($tmp_img); header('Content-Type: image/jpeg'); imagejpeg($image, NULL, 90); imagedestroy($image); } else { echo "Uploaded file was not a JPG image."; } } else { echo "No photo uploaded!"; }} else { echo " <form action='test.php' method='post' enctype='multipart/form-data'> <label for='photo'>User Photo:</label> <input type='file' name='photo' /> <input type='submit' value='Upload a Photo' /> </form> ";} ?>
-
Hello, I have a webcam on a computer running Motion, a webcam streaming program popular in Linux. Motion basically outputs a mjpeg stream. I'd like to use PHP to grab a single jpeg from the mjpeg stream and display it. The reason I'm doing this is because Motion doesn't have any built in password protection. With PHP, I can hide the port and IP address of my home server. I'm trying code provided by the creators of Motion on their website. The code is suppose to grab just a single jpeg from the mjpeg stream, but I get an error when trying to run it on an nginx server locally. <? $camurl="http://127.0.0.1:8080/"; $boundary="\n--"; $f = fopen($camurl,"r") ; if(!$f) { //**** cannot open echo "error"; } else { //**** URL OK while (substr_count($r,"Content-Length") != 2) $r.=fread($f,512); $start = strpos($r,'ΓΏ'); $end = strpos($r,$boundary,$start)-1; $frame = substr("$r",$start,$end - $start); header("Content-type: image/jpeg"); echo $frame; } fclose($f); ?> For reference, this is where I got the code from: http://www.lavrsen.dk/foswiki/bin/view/Motion/MjpegFrameGrabPHP Maybe someone could help me out? I have very little understanding of PHP, and don't understand why the fopen command is returning a fault. In case you're wondering, I've also tried this code snippet. It works, but it's grabbing an entire mjpeg stream. When ran locally on my lan, it works, but when I try the code on a shared host, the shared host computer seems to be trying to download the entire mjpeg stream, which would never complete of course. That's why I'm trying to find code that grabs just a single jpeg instead of streaming the mjpeg. set_time_limit(0); $fp = fsockopen ("xxxx.dyndns.org", 20804, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br>\n"; } else { fputs ($fp, "GET / HTTP/1.0\r\n\r\n"); while ($str = trim(fgets($fp, 4096))) header($str); fpassthru($fp); fclose($fp); }