8000 dokuwiki/inc/JpegMeta.php at old-stable · alexlehm/dokuwiki · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
3008 lines (2613 loc) · 106 KB

JpegMeta.php

File metadata and controls

3008 lines (2613 loc) · 106 KB
<?php
/**
* JPEG metadata reader/writer
*
* @license BSD <http://www.opensource.org/licenses/bsd-license.php>
* @link http://github.com/sd/jpeg-php
* @author Sebastian Delmont <sdelmont@zonageek.com>
* @author Andreas Gohr <andi@splitbrain.org>
* @author Hakan Sandell <hakan.sandell@mydata.se>
* @todo Add support for Maker Notes, Extend for GIF and PNG metadata
*/
// Original copyright notice:
//
// Copyright (c) 2003 Sebastian Delmont <sdelmont@zonageek.com>
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// 3. Neither the name of the author nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
class JpegMeta {
var $_fileName;
var $_fp = null;
var $_type = 'unknown';
var $_markers;
var $_info;
/**
* Constructor
*
* @author Sebastian Delmont <sdelmont@zonageek.com>
*/
function JpegMeta($fileName) {
$this->_fileName = $fileName;
$this->_fp = null;
$this->_type = 'unknown';
unset($this->_info);
unset($this->_markers);
}
/**
* Returns all gathered info as multidim array
*
* @author Sebastian Delmont <sdelmont@zonageek.com>
*/
function & getRawInfo() {
$this->_parseAll();
if ($this->_markers == null) {
return false;
}
return $this->_info;
}
/**
* Returns basic image info
*
* @author Sebastian Delmont <sdelmont@zonageek.com>
*/
function & getBasicInfo() {
$this->_parseAll();
$info = array();
if ($this->_markers == null) {
return false;
}
$info['Name'] = $this->_info['file']['Name'];
if (isset($this->_info['file']['Url'])) {
$info['Url'] = $this->_info['file']['Url'];
$info['NiceSize'] = "???KB";
} else {
$info['Size'] = $this->_info['file']['Size'];
$info['NiceSize'] = $this->_info['file']['NiceSize'];
}
if (@isset($this->_info['sof']['Format'])) {
$info['Format'] = $this->_info['sof']['Format'] . " JPEG";
} else {
$info['Format'] = $this->_info['sof']['Format'] . " JPEG";
}
if (@isset($this->_info['sof']['ColorChannels'])) {
$info['ColorMode'] = ($this->_info['sof']['ColorChannels'] > 1) ? "Color" : "B&W";
}
$info['Width'] = $this->getWidth();
$info['Height'] = $this->getHeight();
$info['DimStr'] = $this->getDimStr();
$dates = $this->getDates();
$info['DateTime'] = $dates['EarliestTime'];
$info['DateTimeStr'] = $dates['EarliestTimeStr'];
$info['HasThumbnail'] = $this->hasThumbnail();
return $info;
}
/**
* Convinience function to access nearly all available Data
* through one function
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function getField($fields) {
if(!is_array($fields)) $fields = array($fields);
$info = false;
foreach($fields as $field){
if(strtolower(substr($field,0,5)) == 'iptc.'){
$info = $this->getIPTCField(substr($field,5));
}elseif(strtolower(substr($field,0,5)) == 'exif.'){
$info = $this->getExifField(substr($field,5));
}elseif(strtolower(substr($field,0,4)) == 'xmp.'){
$info = $this->getXmpField(substr($field,4));
}elseif(strtolower(substr($field,0,5)) == 'file.'){
$info = $this->getFileField(substr($field,5));
}elseif(strtolower(substr($field,0,5)) == 'date.'){
$info = $this->getDateField(substr($field,5));
}elseif(strtolower($field) == 'simple.camera'){
$info = $this->getCamera();
}elseif(strtolower($field) == 'simple.raw'){
return $this->getRawInfo();
}elseif(strtolower($field) == 'simple.title'){
$info = $this->getTitle();
}elseif(strtolower($field) == 'simple.shutterspeed'){
$info = $this->getShutterSpeed();
}else{
$info = $this->getExifField($field);
}
if($info != false) break;
}
if($info === false) $info = $alt;
if(is_array($info)){
if(isset($info['val'])){
$info = $info['val'];
}else{
$info = join(', ',$info);
}
}
return trim($info);
}
/**
* Convinience function to set nearly all available Data
* through one function
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function setField($field, $value) {
if(strtolower(substr($field,0,5)) == 'iptc.'){
return $this->setIPTCField(substr($field,5),$value);
}elseif(strtolower(substr($field,0,5)) == 'exif.'){
return $this->setExifField(substr($field,5),$value);
}else{
return $this->setExifField($field,$value);
}
}
/**
* Convinience function to delete nearly all available Data
* through one function
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function deleteField($field) {
if(strtolower(substr($field,0,5)) == 'iptc.'){
return $this->deleteIPTCField(substr($field,5));
}elseif(strtolower(substr($field,0,5)) == 'exif.'){
return $this->deleteExifField(substr($field,5));
}else{
return $this->deleteExifField($field);
}
}
/**
* Return a date field
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function getDateField($field) {
if (!isset($this->_info['dates'])) {
$this->_info['dates'] = $this->getDates();
}
if (isset($this->_info['dates'][$field])) {
return $this->_info['dates'][$field];
}
return false;
}
/**
* Return a file info field
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function getFileField($field) {
if (!isset($this->_info['file'])) {
$this->_parseFileInfo();
}
if (isset($this->_info['file'][$field])) {
return $this->_info['file'][$field];
}
return false;
}
/**
* Return the camera info (Maker and Model)
*
* @author Andreas Gohr <andi@splitbrain.org>
* @todo handle makernotes
*/
function getCamera(){
$make = $this->getField(array('Exif.Make','Exif.TIFFMake'));
$model = $this->getField(array('Exif.Model','Exif.TIFFModel'));
$cam = trim("$make $model");
if(empty($cam)) return false;
return $cam;
}
/**
* Return shutter speed as a ratio
*
* @author Joe Lapp <joe.lapp@pobox.com>
*/
function getShutterSpeed() {
if (!isset($this->_info['exif'])) {
$this->_parseMarkerExif();
}
if(!isset($this->_info['exif']['ExposureTime'])){
return '';
}
$field = $this->_info['exif']['ExposureTime'];
if($field['den'] == 1) return $field['num'];
return $field['num'].'/'.$field['den'];
}
/**
* Return an EXIF field
*
* @author Sebastian Delmont <sdelmont@zonageek.com>
*/
function getExifField($field) {
if (!isset($this->_info['exif'])) {
$this->_parseMarkerExif();
}
if ($this->_markers == null) {
return false;
}
if (isset($this->_info['exif'][$field])) {
return $this->_info['exif'][$field];
}
return false;
}
/**
* Return an XMP field
*
* @author Hakan Sandell <hakan.sandell@mydata.se>
*/
function getXmpField($field) {
if (!isset($this->_info['xmp'])) {
$this->_parseMarkerXmp();
}
if ($this->_markers == null) {
return false;
}
if (isset($this->_info['xmp'][$field])) {
return $this->_info['xmp'][$field];
}
return false;
}
/**
* Return an Adobe Field
*
* @author Sebastian Delmont <sdelmont@zonageek.com>
*/
function getAdobeField($field) {
if (!isset($this->_info['adobe'])) {
$this->_parseMarkerAdobe();
}
if ($this->_markers == null) {
return false;
}
if (isset($this->_info['adobe'][$field])) {
return $this->_info['adobe'][$field];
}
return false;
}
/**
* Return an IPTC field
*
* @author Sebastian Delmont <sdelmont@zonageek.com>
*/
function getIPTCField($field) {
if (!isset($this->_info['iptc'])) {
$this->_parseMarkerAdobe();
}
if ($this->_markers == null) {
return false;
}
if (isset($this->_info['iptc'][$field])) {
return $this->_info['iptc'][$field];
}
return false;
}
/**
* Set an EXIF field
*
* @author Sebastian Delmont <sdelmont@zonageek.com>
* @author Joe Lapp <joe.lapp@pobox.com>
*/
function setExifField($field, $value) {
if (!isset($this->_info['exif'])) {
$this->_parseMarkerExif();
}
if ($this->_markers == null) {
return false;
}
if ($this->_info['exif'] == false) {
$this->_info['exif'] = array();
}
// make sure datetimes are in correct format
if(strlen($field) >= 8 && strtolower(substr($field, 0, 8)) == 'datetime') {
if(strlen($value) < 8 || $value{4} != ':' || $value{7} != ':') {
$value = date('Y:m:d H:i:s', strtotime($value));
}
}
$this->_info['exif'][$field] = $value;
return true;
}
/**
* Set an Adobe Field
*
* @author Sebastian Delmont <sdelmont@zonageek.com>
*/
function setAdobeField($field, $value) {
if (!isset($this->_info['adobe'])) {
$this->_parseMarkerAdobe();
}
if ($this->_markers == null) {
return false;
}
if ($this->_info['adobe'] == false) {
$this->_info['adobe'] = array();
}
$this->_info['adobe'][$field] = $value;
return true;
}
/**
* Calculates the multiplier needed to resize the image to the given
* dimensions
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function getResizeRatio($maxwidth,$maxheight=0){
if(!$maxheight) $maxheight = $maxwidth;
$w = $this->getField('File.Width');
$h = $this->getField('File.Height');
$ratio = 1;
10BC8
if($w >= $h){
if($w >= $maxwidth){
$ratio = $maxwidth/$w;
}elseif($h > $maxheight){
$ratio = $maxheight/$h;
}
}else{
if($h >= $maxheight){
$ratio = $maxheight/$h;
}elseif($w > $maxwidth){
$ratio = $maxwidth/$w;
}
}
return $ratio;
}
/**
* Set an IPTC field
*
* @author Sebastian Delmont <sdelmont@zonageek.com>
*/
function setIPTCField($field, $value) {
if (!isset($this->_info['iptc'])) {
$this->_parseMarkerAdobe();
}
if ($this->_markers == null) {
return false;
}
if ($this->_info['iptc'] == false) {
$this->_info['iptc'] = array();
}
$this->_info['iptc'][$field] = $value;
return true;
}
/**
* Delete an EXIF field
*
* @author Sebastian Delmont <sdelmont@zonageek.com>
*/
function deleteExifField($field) {
if (!isset($this->_info['exif'])) {
$this->_parseMarkerAdobe();
}
if ($this->_markers == null) {
return false;
}
if ($this->_info['exif'] != false) {
unset($this->_info['exif'][$field]);
}
return true;
}
/**
* Delete an Adobe field
*
* @author Sebastian Delmont <sdelmont@zonageek.com>
*/
function deleteAdobeField($field) {
if (!isset($this->_info['adobe'])) {
$this->_parseMarkerAdobe();
}
if ($this->_markers == null) {
return false;
}
if ($this->_info['adobe'] != false) {
unset($this->_info['adobe'][$field]);
}
return true;
}
/**
* Delete an IPTC field
*
* @author Sebastian Delmont <sdelmont@zonageek.com>
*/
function deleteIPTCField($field) {
if (!isset($this->_info['iptc'])) {
$this->_parseMarkerAdobe();
}
if ($this->_markers == null) {
return false;
}
if ($this->_info['iptc'] != false) {
unset($this->_info['iptc'][$field]);
}
return true;
}
/**
* Get the image's title, tries various fields
*
* @param int $max maximum number chars (keeps words)
* @author Andreas Gohr <andi@splitbrain.org>
*/
function getTitle($max=80){
$cap = '';
// try various fields
$cap = $this->getField(array('Iptc.Headline',
'Iptc.Caption',
'Xmp.dc:title',
'Exif.UserComment',
'Exif.TIFFUserComment',
'Exif.TIFFImageDescription',
'File.Name'));
if (empty($cap)) return false;
if(!$max) return $cap;
// Shorten to 80 chars (keeping words)
$new = preg_replace('/\n.+$/','',wordwrap($cap, $max));
if($new != $cap) $new .= '...';
return $new;
}
/**
* Gather various date fields
*
* @author Sebastian Delmont <sdelmont@zonageek.com>
*/
function getDates() {
$this->_parseAll();
if ($this->_markers == null) {
if (@isset($this->_info['file']['UnixTime'])) {
$dates['FileModified'] = $this->_info['file']['UnixTime'];
$dates['Time'] = $this->_info['file']['UnixTime'];
$dates['TimeSource'] = 'FileModified';
$dates['TimeStr'] = date("Y-m-d H:i:s", $this->_info['file']['UnixTime']);
$dates['EarliestTime'] = $this->_info['file']['UnixTime'];
$dates['EarliestTimeSource'] = 'FileModified';
$dates['EarliestTimeStr'] = date("Y-m-d H:i:s", $this->_info['file']['UnixTime']);
$dates['LatestTime'] = $this->_info['file']['UnixTime'];
$dates['LatestTimeSource'] = 'FileModified';
$dates['LatestTimeStr'] = date("Y-m-d H:i:s", $this->_info['file']['UnixTime']);
return $dates;
}
return false;
}
$dates = array();
$latestTime = 0;
$latestTimeSource = "";
$earliestTime = time();
$earliestTimeSource = "";
if (@isset($this->_info['exif']['DateTime'])) {
$dates['ExifDateTime'] = $this->_info['exif']['DateTime'];
$aux = $this->_info['exif']['DateTime'];
$aux{4} = "-";
$aux{7} = "-";
$t = strtotime($aux);
if ($t && $t > $latestTime) {
$latestTime = $t;
$latestTimeSource = "ExifDateTime";
}
if ($t && $t < $earliestTime) {
$earliestTime = $t;
$earliestTimeSource = "ExifDateTime";
}
}
if (@isset($this->_info['exif']['DateTimeOriginal'])) {
$dates['ExifDateTimeOriginal'] = $this->_info['exif']['DateTime'];
$aux = $this->_info['exif']['DateTimeOriginal'];
$aux{4} = "-";
$aux{7} = "-";
$t = strtotime($aux);
if ($t && $t > $latestTime) {
$latestTime = $t;
$latestTimeSource = "ExifDateTimeOriginal";
}
if ($t && $t < $earliestTime) {
$earliestTime = $t;
$earliestTimeSource = "ExifDateTimeOriginal";
}
}
if (@isset($this->_info['exif']['DateTimeDigitized'])) {
$dates['ExifDateTimeDigitized'] = $this->_info['exif']['DateTime'];
$aux = $this->_info['exif']['DateTimeDigitized'];
$aux{4} = "-";
$aux{7} = "-";
$t = strtotime($aux);
if ($t && $t > $latestTime) {
$latestTime = $t;
$latestTimeSource = "ExifDateTimeDigitized";
}
if ($t && $t < $earliestTime) {
$earliestTime = $t;
$earliestTimeSource = "ExifDateTimeDigitized";
}
}
if (@isset($this->_info['iptc']['DateCreated'])) {
$dates['IPTCDateCreated'] = $this->_info['iptc']['DateCreated'];
$aux = $this->_info['iptc']['DateCreated'];
$aux = substr($aux, 0, 4) . "-" . substr($aux, 4, 2) . "-" . substr($aux, 6, 2);
$t = strtotime($aux);
if ($t && $t > $latestTime) {
$latestTime = $t;
$latestTimeSource = "IPTCDateCreated";
}
if ($t && $t < $earliestTime) {
$earliestTime = $t;
$earliestTimeSource = "IPTCDateCreated";
}
}
if (@isset($this->_info['file']['UnixTime'])) {
$dates['FileModified'] = $this->_info['file']['UnixTime'];
$t = $this->_info['file']['UnixTime'];
if ($t && $t > $latestTime) {
$latestTime = $t;
$latestTimeSource = "FileModified";
}
if ($t && $t < $earliestTime) {
$earliestTime = $t;
$earliestTimeSource = "FileModified";
}
}
$dates['Time'] = $earliestTime;
$dates['TimeSource'] = $earliestTimeSource;
$dates['TimeStr'] = date("Y-m-d H:i:s", $earliestTime);
$dates['EarliestTime'] = $earliestTime;
$dates['EarliestTimeSource'] = $earliestTimeSource;
$dates['EarliestTimeStr'] = date("Y-m-d H:i:s", $earliestTime);
$dates['LatestTime'] = $latestTime;
$dates['LatestTimeSource'] = $latestTimeSource;
$dates['LatestTimeStr'] = date("Y-m-d H:i:s", $latestTime);
return $dates;
}
/**
* 10BC8 Get the image width, tries various fields
*
* @author Sebastian Delmont <sdelmont@zonageek.com>
*/
function getWidth() {
if (!isset($this->_info['sof'])) {
$this->_parseMarkerSOF();
}
if ($this->_markers == null) {
return false;
}
if (isset($this->_info['sof']['ImageWidth'])) {
return $this->_info['sof']['ImageWidth'];
}
if (!isset($this->_info['exif'])) {
$this->_parseMarkerExif();
}
if (isset($this->_info['exif']['PixelXDimension'])) {
return $this->_info['exif']['PixelXDimension'];
}
return false;
}
/**
* Get the image height, tries various fields
*
* @author Sebastian Delmont <sdelmont@zonageek.com>
*/
function getHeight() {
if (!isset($this->_info['sof'])) {
$this->_parseMarkerSOF();
}
if ($this->_markers == null) {
return false;
}
if (isset($this->_info['sof']['ImageHeight'])) {
return $this->_info['sof']['ImageHeight'];
}
if (!isset($this->_info['exif'])) {
$this->_parseMarkerExif();
}
if (isset($this->_info['exif']['PixelYDimension'])) {
return $this->_info['exif']['PixelYDimension'];
}
return false;
}
/**
* Get an dimension string for use in img tag
*
* @author Sebastian Delmont <sdelmont@zonageek.com>
*/
function getDimStr() {
if ($this->_markers == null) {
return false;
}
$w = $this->getWidth();
$h = $this->getHeight();
return "width='" . $w . "' height='" . $h . "'";
}
/**
* Checks for an embedded thumbnail
*
* @author Sebastian Delmont <sdelmont@zonageek.com>
*/
function hasThumbnail($which = 'any') {
if (($which == 'any') || ($which == 'exif')) {
if (!isset($this->_info['exif'])) {
$this->_parseMarkerExif();
}
if ($this->_markers == null) {
return false;
}
if (isset($this->_info['exif']) && is_array($this->_info['exif'])) {
if (isset($this->_info['exif']['JFIFThumbnail'])) {
return 'exif';
}
}
}
if ($which == 'adobe') {
if (!isset($this->_info['adobe'])) {
$this->_parseMarkerAdobe();
}
if ($this->_markers == null) {
return false;
}
if (isset($this->_info['adobe']) && is_array($this->_info['adobe'])) {
if (isset($this->_info['adobe']['ThumbnailData'])) {
return 'exif';
}
}
}
return false;
}
/**
* Send embedded thumbnail to browser
*
* @author Sebastian Delmont <sdelmont@zonageek.com>
*/
function sendThumbnail($which = 'any') {
$data = null;
if (($which == 'any') || ($which == 'exif')) {
if (!isset($this->_info['exif'])) {
$this->_parseMarkerExif();
}
if ($this->_markers == null) {
return false;
}
if (isset($this->_info['exif']) && is_array($this->_info['exif'])) {
if (isset($this->_info['exif']['JFIFThumbnail'])) {
$data =& $this->_info['exif']['JFIFThumbnail'];
}
}
}
if (($which == 'adobe') || ($data == null)){
if (!isset($this->_info['adobe'])) {
$this->_parseMarkerAdobe();
}
if ($this->_markers == null) {
return false;
}
if (isset($this->_info['adobe']) && is_array($this->_info['adobe'])) {
if (isset($this->_info['adobe']['ThumbnailData'])) {
$data =& $this->_info['adobe']['ThumbnailData'];
}
}
}
if ($data != null) {
header("Content-type: image/jpeg");
echo $data;
return true;
}
return false;
}
/**
* Save changed Metadata
*
* @author Sebastian Delmont <sdelmont@zonageek.com>
* @author Andreas Gohr <andi@splitbrain.org>
*/
function save($fileName = "") {
if ($fileName == "") {
$tmpName = tempnam(dirname($this->_fileName),'_metatemp_');
$this->_writeJPEG($tmpName);
if (@file_exists($tmpName)) {
return io_rename($tmpName, $this->_fileName);
}
} else {
return $this->_writeJPEG($fileName);
}
return false;
}
/*************************************************************/
/* PRIVATE FUNCTIONS (Internal Use Only!) */
/*************************************************************/
/*************************************************************/
function _dispose() {
$this->_fileName = $fileName;
$this->_fp = null;
$this->_type = 'unknown';
unset($this->_markers);
unset($this->_info);
}
/*************************************************************/
function _readJPEG() {
unset($this->_markers);
//unset($this->_info);
$this->_markers = array();
//$this->_info = array();
$this->_fp = @fopen($this->_fileName, 'rb');
if ($this->_fp) {
if (file_exists($this->_fileName)) {
$this->_type = 'file';
}
else {
$this->_type = 'url';
}
} else {
$this->_fp = null;
return false; // ERROR: Can't open file
}
// Check for the JPEG signature
$c1 = ord(fgetc($this->_fp));
$c2 = ord(fgetc($this->_fp));
if ($c1 != 0xFF || $c2 != 0xD8) { // (0xFF + SOI)
$this->_markers = null;
return false; // ERROR: File is not a JPEG
}
$count = 0;
$done = false;
$ok = true;
while (!$done) {
$capture = false;
// First, skip any non 0xFF bytes
$discarded = 0;
$c = ord(fgetc($this->_fp));
while (!feof($this->_fp) && ($c != 0xFF)) {
$discarded++;
$c = ord(fgetc($this->_fp));
}
// Then skip all 0xFF until the marker byte
do {
$marker = ord(fgetc($this->_fp));
} while (!feof($this->_fp) && ($marker == 0xFF));
if (feof($this->_fp)) {
return false; // ERROR: Unexpected EOF
}
if ($discarded != 0) {
return false; // ERROR: Extraneous data
}
$length = ord(fgetc($this->_fp)) * 256 + ord(fgetc($this->_fp));
if (feof($this->_fp)) {
return false; // ERROR: Unexpected EOF
}
if ($length < 2) {
return false; // ERROR: Extraneous data
}
$length = $length - 2; // The length we got counts itself
switch ($marker) {
case 0xC0: // SOF0
case 0xC1: // SOF1
case 0xC2: // SOF2
case 0xC9: // SOF9
case 0xE0: // APP0: JFIF data
case 0xE1: // APP1: EXIF or XMP data
case 0xED: // APP13: IPTC / Photoshop data
$capture = true;
break;
case 0xDA: // SOS: Start of scan... the image itself and the last block on the file
$capture = false;
$length = -1; // This field has no length... it includes all data until EOF
$done = true;
break;
default:
$capture = true;//false;
break;
}
$this->_markers[$count] = array();
$this->_markers[$count]['marker'] = $marker;
$this->_markers[$count]['length'] = $length;
if ($capture) {
if ($length)
$this->_markers[$count]['data'] =& fread($this->_fp, $length);
else
$this->_markers[$count]['data'] = "";
}
elseif (!$done) {
$result = @fseek($this->_fp, $length, SEEK_CUR);
// fseek doesn't seem to like HTTP 'files', but fgetc has no problem
if (!($result === 0)) {
for ($i = 0; $i < $length; $i++) {
fgetc($this->_fp);
}
}
}
$count++;
}
if ($this->_fp) {
fclose($this->_fp);
$this->_fp = null;
}
return $ok;
}
0