php.de

Zurück   php.de > Webentwicklung > PHP Einsteiger > PHP Tipps 2008

 
 
LinkBack Themen-Optionen Thema bewerten
Alt 27.12.2008, 15:00  
Neuer Benutzer
 
Registriert seit: 27.12.2008
Beiträge: 2
rolfer befindet sich auf einem aufstrebenden Ast
Standard Bilder von Webcam auf eigenem Webspace speichern

Hallo zusammen

Ich möchte Bilder von einer Webcam mit einem Php-script auf meine WEbseite saugen, immer wenn die webseite aufgerufen wird und in einem Ordner speichern.
dazu habe ich leider nirgends etwas gefunden, das funktioniert.

Danke.
rolfer ist offline  
Sponsor Mitteilung
PHP Code Flüsterer

Registriert seit: 21.08.2005
Beiträge: 4682
PHP-Kenntnisse:
Fortgeschritten

Alt 27.12.2008, 15:08  
Erfahrener Benutzer
 
Registriert seit: 06.09.2008
Beiträge: 189
#Avedo befindet sich auf einem aufstrebenden Ast
Standard

Naja das ist auch nicht ohne weiteres möglich. Die Bilder der Webcam müsen auf einem Rechner abgelegt werden, der über das Netz erreichbar ist. Die Bilder können dann nach und nach via HTTP in einen Ordner auf dem Server geladen werden. Mit einem weiteren Request kann man dafür sorgen, dass die Bilder auf dem Zielserver gelöscht werden. So würde ich das ganze lösen.
MfG, Andy
__________________
I'm so tired of slitting the throats of people calling me a violent psychopath.
#Avedo ist offline  
Alt 27.12.2008, 15:26  
Neuer Benutzer
 
Registriert seit: 27.12.2008
Beiträge: 2
rolfer befindet sich auf einem aufstrebenden Ast
Standard

Es geht mir nur darum, wie ich per http die bilder vom andern server hole und per php auf meinen webspace speichere, das andere funktioniert schon.
Ich habe schon einen Versuch gemacht: aber das funktioniert nicht sondern speichert nur ein leeres bild im ordner:
<?
ob_start();
$fp = fopen("http://www.smdk.ch/webcam/live.jpg", "rb");
fpassthru($fp);
fclose($fp);
$file = ob_get_contents();
ob_end_clean();

$fp = fopen("live.jpg", "wb+");
fwrite($fp, $file);
fclose($fp);
?>
<img src="live.jpg">

danke.
rolfer ist offline  
Alt 27.12.2008, 16:03  
Erfahrener Benutzer
 
Registriert seit: 06.09.2008
Beiträge: 189
#Avedo befindet sich auf einem aufstrebenden Ast
Standard

Du kannst hier nicht mit den file Funktionen arbeiten, da es sein könnt, dass auf dem Zielserver allow_url_fopen auf false gesetzt ist. Du müsstest also über eine Socket-Verbindung gehen. Dazu habe ich mal eine Klasse geschrieben, die du gerne nutzen kannst.
MfG, Andy


HttpConnect.php
PHP-Code:
<?php

/***
* Class HttpConnect 
*
* The HttpConnect class allows easy connecting 
* to a server. After connecting to your server
* you are able to send a post, get or a head command.
* So it is possible to send or to get different information
* to or from the server. Finally it is important to mention that 
* this class supports secure sockets layer connections (ssl).
*  
* @package HttpConnect
* @version 1.0
* @author Andreas Wilhelm <Andreas2209@web.de>
* @copyright Andreas Wilhelm
**/ 
class HttpConnect
{
    
// protected class variables
    
private $host;
    private 
$port
    
    private 
$ssl;
    
    
// tip by Denis Wronka, who said, that many servers need a referrer
    
private $referrer;
    
    private 
$logStats;
    private 
$log;

    
/**
    * connect() - Sets the server-variables
    *
    * @access: public
    * @param Str $host
    * @param Int $port
    * @param Boo $ssl
    * @param Boo $log    
    * @param Str $referrer    
    * @return NONE
    */
    
public function connect($host='localhost'$port=80$ssl=false$log=false$referrer="PHP/HTTP-Class")
    {
        
// set server-variables
        
$this->host $host;
        
$this->port $port;
        
        
$this->ssl $ssl;
        
$this->referrer $referrer;
        
        
// set if the connection with the server should be logged
        
$this->logStats $log;
    }

    
/**
    * login() - Connects to the server
    *
    * @access: private
    * @param Str $host
    * @param Int $port
    * @return Handle
    */
    
private function login()
    {    
        if (
$this->ssl == true)
        {    
            
// use ssl-connection and save connection handle
            
$handle = @fsockopen('ssl://'.$this->host$this->port);
            
            
// throw error in case of failure
            
if (!$handle)
            {
                throw new 
Exception("SSL-connection failed.\n");
            }
        }

        else
        {
            
// connection handle is saved to $handle
            
$handle = @fsockopen($this->host$this->port);
                        
            
// throw error in case of failure
            
if (!$handle)
            {
                throw new 
Exception("Connection failed.\n");
            }
        }
        
        
        
// switch to non-blocking mode - just return data no response
        
set_socket_blocking($handletrue);
        
        
// set timeout of the server connection
        
stream_set_timeout($handle0200000);
        
        return 
$handle;
    }

    
/**
    * auth() - Creates a connection to a secured server
    *
    * @access: private
    * @param Str $user
    * @param Str $password
    * @return String
    */
    
private function auth($user$password)
    {        
        if( !empty(
$user) )
        {
            
$auth 'Authorization: Basic '.base64_encode($user.':'.$password)."\r\n";
        }

        else
        {
            
$auth '';
        }
        
        return 
$auth;
    }
  
    
/**
    * logout() - Closes the connection
    *
    * @access: private
    * @return NONE
    */      
    
private function logout($handle)
    {
        
fclose($handle);
    }

    
/**
    * cmd() - Sends a command to the server
    *
    * @access: private
    * @param Str $cmd
    * @return NONE
    */
    
private function cmd($handle$cmd)
    {
        
// send the request
        
fputs($handle$cmd);
        
        
// log the request
        
$this->log("-> $cmd");
    }
    
    
/**
    * readSock() - Reads out the response from the server
    *
    * @access: private
    * @return String
    */
    
private function readSock($handle)
    {    
        
$response "";

        while(!
feof($handle))
        {
            
$response .= fread($handle1025);
        }
        
        
$this->log($response);
        
        return 
$response;
    }
            
    
/**
    * divideReply() - Spilts up the reply into the different information
    *
    * @access: private
    * @param Str $reply
    * @return Array
    */
    
private function divideReply$reply )
    {    
        
// check HTTP-Version and status-code
        
if( !preg_match('/^HTTP\/(1\.[01]) ([1-5][0-9]{2})/'$reply$match) ) 
        {
            return 
false;
        }
        
        
// split header and body
        
$hb strpos($reply"\r\n")+2;
        
$cb strpos($reply"\r\n\r\n")+4;
        
        
// write data into an array
        
$parsed = array(
            
'HTTP_VERSION'  => $match[1],
            
'STATUS_CODE'   => $match[2],
            
'HEADER_FIELDS' => array(),
            
'CONTENT'       => (string) substr($reply$cb)
        );
        
        
// split up header-fields
        
$headerFields explode("\r\n"preg_replace('/\x0D\x0A[\x09\x20]+/'' 'substr($reply$hb$cb-$hb-4)));
        foreach( 
$headerFields as $headerField 
        {
            if( 
preg_match('/([^:]+):(.+)/m'$headerField$match) ) 
            {
                
$parsed['HEADER_FIELDS'][$this->getName($match[1])] = trim($match[2]);
            }
        }
        
        
// check if tranfere-encoding is chunked
        
if( isset($parsed['HEADER_FIELDS']['Transfer-Encoding']) && $parsed['HEADER_FIELDS']['Transfer-Encoding'] == 'chunked' )    
        {
            
// encode chunked data
            
return $this->decodeChunked($parsed);
        }
        
        return 
$parsed;
    }
    
    
/**
    * getName() - Returns the name of a received HTTP-header-field
    *
    * @access: private
    * @param Str $string
    * @return String
    */
    
private function getName($string)
    {
        return 
preg_replace('/(?<=^|[\x09\x20\x2D])./e''strtoupper("\0")'strtolower(trim($string)));
    }  
    
    
/**
    * decodeChunked() - Decodes body in chunked encoding
    *
    * @access: private
    * @param Arr $chunked
    * @return Array
    */
    
private function decodeChunked($chunked)
    {    
        
$body '';
        
$length NULL;
        
$size NULL;
        
        
// save chunked body to a variable
        
$chunk $chunked['CONTENT'];

        while(
true
        {
            
// get next occurrence of CRLF
            
$pos = @strpos($chunk"\r\n"0);

            if( !(
$pos === false) && ($size === NULL) ) 
            {
                
// get the size of following chunk from hex
                
$size hexdec(substr($chunk0$pos));
                
                
// get the following chunk
                
$body .= substr($chunk$pos+2$size);
                
                
// update the content not encoded
                
$chunk substr($chunk$pos+2+$size);
                
                
// update content-length
                
$length += $size;
                
                
// reset chunk-size
                
$size NULL;
            }
            
            else 
            {
                
// leave loop
                
break;
            }
        }
        
        
// set right Content
        
$chunked['CONTENT'] = $body;
        
        
// set right Content-Length
        
$chunked['HEADER_FIELDS']['Content-Length'] = $length;
        
        
// change Transfere-Encoding
        
$chunked['HEADER_FIELDS']['Transfer-Encoding'] = 'token';
    
        return 
$chunked;
    }  
            
    
/**
    * head() - Returns the HTTP-header like a GET or POST reply but without the file
    *
    * @access: public
    * @param Str $uri
    * @param Mix $params
    * @param Mix $cookies
    * @param Str $user
    * @param Str $password
    * @return Array
    */
    
public function head($uri='/'$params=false$cookies=false$user=""$password="")
    {
        
// login to the server
        
$handle $this->login();
        
        
// create authorization-string
        
$auth $this->auth($user$password);
        
        
// prepare uri for request
        
if (empty($uri) || ($uri{0}!='/'))
        {
            
$uri "/$uri";
        }
                
        
// check if parameters should be used and prepare them for request
        
if (($params!=false) && (!empty($params)))
        {
            
$params "?$params";
        }
        
        else
        {
            
$params '';
        }
        
        
// check if cookies should be used and prepare them for request
        
if (($cookies!=false) && (!empty($cookies)))
        {
                
$cookies "Cookie: $cookies\r\n";
        }
        
        else
        {
            
$cookies '';
        }
        
        
// prepare host-data
        
$host $this->host;
        
        if (
$this->port != 80)
        {
            
$host .= ':'.$this->port;
        }
        
        
// send request to the server
        
$this->cmd($handle"HEAD $uri"."$params HTTP/1.1\r\n");
        
$this->cmd($handle"Host: $host\r\n".$cookies.$auth);
        
$this->cmd($handle"User-Agent: ".$this->referrer."\r\n");
        
$this->cmd($handle"Connection: close\r\n\r\n");
        
        
// get server response
        
$reply $this->readSock($handle);
        
        
// end connection to the server
        
$this->logout($handle);
        
        
// prepare headers
        
$data $this->divideReply($reply);
        
        return 
$data;
    }
            
    
/**
    * get() - Returns the HTTP-header and the output of the file
    *
    * @access: public
    * @param Str $uri
    * @param Mix $params
    * @param Mix $cookies
    * @param Str $user
    * @param Str $password
    * @return Array
    */
    
public function get($uri='/'$params=false$cookies=false$user=""$password="")
    {
        
// login to the server
        
$handle $this->login();
        
        
// create authorization-string
        
$auth $this->auth($user$password);
        
        
// prepare uri for request
        
if (empty($uri) || ($uri{0}!='/'))
        {
            
$uri "/$uri";
        }
                
        
// check if parameters should be used and prepare them for request
        
if (($params!=false) && (!empty($params)))
        {
            
$params "?$params";
        }
        
        else
        {
            
$params '';
        }
        
        
// check if cookies should be used and prepare them for request
        
if (($cookies!=false) && (!empty($cookies)))
        {
                
$cookies "Cookie: $cookies\r\n";
        }
        
        else
        {
            
$cookies '';
        }
        
        
// prepare host-data
        
$host $this->host;
        if (
$this->port != 80)
        {
            
$host .= ':'.$this->port;
        }
        
        
// send request to the server
        
$this->cmd($handle"GET $uri"."$params HTTP/1.1\r\n");
        
$this->cmd($handle"Host: $host\r\n".$cookies.$auth);
        
$this->cmd($handle"User-Agent: ".$this->referrer."\r\n");
        
$this->cmd($handle"Connection: close\r\n\r\n");
        
        
// get server response
        
$reply $this->readSock($handle);
        
        
// end connection to the server
        
$this->logout($handle);
        
        
// prepare headers and file
        
$data $this->divideReply($reply);
        
        return 
$data;
    }
            
    
/**
    * post() - Returns the HTTP-header and the output of the file
    *
    * @access: public
    * @param Str $uri
    * @param Mix $params
    * @param Mix $cookies
    * @param Mix $fileparams
    * @param Mix $mimes
    * @param Str $user
    * @param Str $password
    * @return Array
    */
    
public function post($uri='/'$params=false$cookies=false$fileparams=false$mimes=false$user='',$password='')
    {
        
// login to the server
        
$handle $this->login();
        
        
// create authorization-string
        
$auth $this->auth($user$password);
        
        
// prepare uri for request
        
if (empty($uri) || ($uri{0}!='/'))
        {
            
$uri "/$uri";
        }
                
        
// check if parameters should be used and prepare them for request
        
if (($params!=false) && (!empty($params)))
        {
            
$params "?$params";
        }
        
        else
        {
            
$params '';
        }
        
        
// check if cookies should be used and prepare them for request
        
if (($cookies!=false) && (!empty($cookies)))
        {
                
$cookies "Cookie: $cookies\r\n";
        }
        
        else
        {
            
$cookies '';
        }
        
        
// prepare host-data
        
$host $this->host;
        if (
$this->port != 80)
        {
            
$host .= ':'.$this->port;
        }
        
        if ((
$fileparams==false) || (empty($fileparams)))
        {
            if ((
$params!=false) && (!empty($params)))
            {
                
//prepare the attribut Content-Length
                
$length strlen($params);
                
                
// send request and parameters to the server
                
$this->cmd($handle"POST ".$uri." HTTP/1.1\r\n");
                
$this->cmd($handle"Host: $host\r\n".$cookies.$auth);
                
$this->cmd($handle"User-Agent: ".$this->referrer."\r\n");
                
$this->cmd($handle"Connection: close\r\n");
                
                
$this->cmd($handle"Content-Type: application/x-www-form-urlencoded\r\n");
                
$this->cmd($handle"Content-Length: ".$length."\r\n\r\n".$params);
            }

            else
            {
                
// send request without parameters
                
$this->cmd($handle"POST ".$uri." HTTP/1.1\r\n");
                
$this->cmd($handle"Host: $host\r\n".$cookies.$auth);
                
$this->cmd($handle"User-Agent: ".$this->referrer."\r\n");
                
$this->cmd($handle"Connection: close\r\n");
            }
        }
        
        else
        {
            
// save the name and the value of the parameters to an array
            
$res split('&',$params);
            foreach(
$res as $v)
            {
                list(
$name$value) = split('='$v);
                
$param[$name] = $value;
            }
            
            
// do the same with the file-parameters
            
$rep split('&',$fileparams);
            foreach(
$rep as $v)
            {
                list(
$name$value) = split('='$v);
                
$fparam[][$name] = $value;
            }
            
            
// save given mimetypes to an array
            
if ( ($mimes!=false) && (!empty($mimes)) )
            {
                
$mimeparam split(','$mimes);
            }
            
            
// create array for mimetypes if no exist
            
if (!isset($mimeparam))
            {
                
$mimeparam = array();
            }
            
            
// fill empty mimetype-spaces with standrad-mimetype
            
while (count($mimeparam) < count($fparam))            
            {
                
$mimeparam[]='application/octet-stream';
            }            
            
            
// the boundary seperates the different blocks holding the parameters
            
$boundary md5(uniqid());
            
$content '';            
            
            
// start counter
            
$key 0;

            
// prepare the blocks with the file-parameters
            
foreach($fparam as $name => $fname)
            {
                
$fp fopen($fname'r');
                
$fcontent fread($fpfilesize($fname));
                
$content .= '--'.$boundary."\r\n";
                
$content .= 'Content-Disposition: form-data; name="'.$name.'"; filename="'.$fname.'"'."\r\n";
                
$content .= 'Content-Type: '.$mimeparam[$key]."\r\n\r\n";
                
$content .= $filecontent."\r\n";
    
                
$key++;
            }
            
            
// prepare the blocks for the parameters
            
foreach($param as $name => $value)
            {
                
$content .= '--'.$boundary."\r\n";
                
$content .= 'Content-Disposition: form-data; name="'.$name.'"'."\r\n\r\n";
                
                if (!empty(
$value))
                {
                    
$content .= $value."\r\n";
                }
            }
            
            
$content .= '--'.$boundary."--\r\n";
            
            
// get length of the content
            
$length strlen($content);
            
            
// send standard data
            
$this->cmd($handle"POST ".$uri." HTTP/1.1\r\n");
            
$this->cmd($handle"Host: $host\r\n".$cookies.$auth);
            
$this->cmd($handle"User-Agent: ".$this->referrer."\r\n");
            
$this->cmd($handle"Connection: close\r\n");                        
                        
            
// send the the parameters and file-parameters
            
$this->cmd($handle"Content-Type: multipart/form-data; boundary=".$boundary."\r\n");
            
$this->cmd($handle"Content-Length: ".$length."\r\n\r\n");
            
$this->cmd($handle$content);
        }
        
        
// get server response
        
$reply $this->readSock($handle);
        
        
// end connection to the server
        
$this->logout($handle);
        
        
// prepare headers and file
        
$data $this->divideReply($reply);
        
        return 
$data;
    }
            
    
/**
    * log() - Saves all request and responses into $log
    *
    * @access: private
    * @param Str $str
    * @return NONE
    */
    
private function log($str)
    {
        if(
$this->logStats)
        {
            
$this->log .= $str;
        }
    }
            
    
/**
    * __toString() - Prints out the logged data
    *
    * @access: public
    * @return String
    */
    
public function __toString()
    {
        return 
$this->log;
    }
}
?>
__________________
I'm so tired of slitting the throats of people calling me a violent psychopath.
#Avedo ist offline  
 


Themen-Optionen
Thema bewerten
Thema bewerten:

Forumregeln
Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are an
Gehe zu

Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
Bilder ohne DB sicher speichern Diet PHP Tipps 2005 6 25.03.2009 00:07
Zip und php.ini & Wie Bilder speichern? Igäl PHP Tipps 2008 6 23.08.2007 12:52
Bilder von einem Webspace auf den andern transferieren. PHP-Fortgeschrittene 2 23.10.2006 16:58
Bilder speichern m-elssner PHP Tipps 2006 1 19.06.2006 18:00
Bilder aus Dir in mehrdim. Array speichern Riot PHP Tipps 2006 11 05.06.2006 23:12
Bilder temporär speichern FireFIghter PHP Tipps 2006 6 11.03.2006 12:57
Webcam Bilder abfangen! Aber wie? Broadcast PHP Tipps 2005-2 4 19.07.2005 13:24
[Erledigt] Bild von anderer Webseite laden und auf eigenem Webspace... PHP Tipps 2005-2 5 09.06.2005 22:56
Bilder speichern statt anzeigen... PHP Tipps 2005 3 25.04.2005 15:22
Externe Datei auslesen und auf Webspace speichern Beitragsarchiv 9 19.04.2005 16:44
Bilder in Datenbank speichern Beatbox Datenbanken 2 29.03.2005 15:32
Script um Bilder einzufügen und auf dem Server speichern PHP Tipps 2004 2 23.10.2004 00:43
Bilder über php inMySqlDB speichern PHP Tipps 2004 1 10.09.2004 23:11
Bilder in Datenbank speichern PHP Tipps 2004 11 05.08.2004 10:58
[Erledigt] Bilder nur auf eigenem Server anzeigen lassen Server, Hosting und Workstations 9 30.06.2004 15:20

Besucher kamen über folgende Suchanfragen bei Google auf diese Seite
webcam bilder auf server speichern, php bild von webcam speichern, http://www.php.de/php-tipps-2008/50111-bilder-von-webcam-auf-eigenem-webspace-speichern.html, webcam cmd, webcam webspace, php webcam bild speichern, php webcam, cmd webcam, webspace für webcam, webcam php, javascript webcam bild aus stream speichern, webspace webcam, bilder von webcam auf webspace, webcam auf server speichern, octet stream webcam, webcam bilder auf webspace, webcam handle, webcam streamen webspace, webcam bild speichern php, \webcam bild\ \auf server speichern\ php script

Alle Zeitangaben in WEZ +2. Es ist jetzt 18:17 Uhr.




Powered by vBulletin® Version 3.7.2 (Deutsch)
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
Aprilia-Forum, Aquaristik-Forum, Liebeskummer-Forum, Zierfisch-Forum, Geizkragen-Forum