Location: PHPKode > projects > FiForms Framework > FiForms/FiForms-includes/FiForms_iFile.inc.php
<?php

/*
*******************************************************************************

    FiForms -- A collection of PHP classes designed 
    to facilitate rapid development of web-database software

    Copyright (C) 2003-2008  Daniel McFeeters

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.

    You should have received a copy of the GNU General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


    The original author of this library can be contacted at the following 
    address:

    Daniel McFeeters
    182 Baker Rd.
    Faubush, KY 42544-6526
    email:databases [at] fiforms [dot] org
    http://www.fiforms.org/


iFile class
Project Started May 4, 2003
*******************************************************************************
FiForms_iFile.inc.php

iFile Definition File

iFile is an HTML File upload input box

*******************************************************************************
*/

require_once("FiForms_iInput.inc.php");

/* ?><code><?php */

$FIFORM_XML_INPUTS[] = 'f:iFile';

class iFile extends iInput
// a File Upload box
{
    public $maxSize;
    public $showAsImage;
    public $multiField;
    public $ROwidth;
    public $primaryKeyFilter;

    function iFile()
    {
        $this->type = "file";
        $this->multiField = true;
        $this->maxSize = 2000000;
        $this->ROwidth = 120;
        $this->showAsImage = false;

        $this->iInput(func_get_args());
        $this->useHex = TRUE;
        $this->isBin = TRUE;
    }

    function setValue($value)
    {
        if($_GET['FIFORMS_IFILE_DOWNLOAD'] == 'DOWNLOAD' && $_GET['FIFORMS_IFILE_FIELD'] == $this->dbField)
        {
            header('Content-type: application/octet-stream');
            header('Content-Disposition: inline; filename='.$this->dbField.'.jpg');
            echo $value;
            die();
        }
        else if($_GET['FIFORMS_IFILE_DOWNLOAD'] == 'IMAGE' &&
                $_GET['FIFORMS_IFILE_FIELD'] == $this->dbField)
        {
            header('Content-type: image/jpeg');
            header('Content-Disposition: inline; filename='.$this->dbField.'.jpg');
            echo $value;
            die();
        }
        else
        {
            $this->value = (strlen($value)/1000)."K";
        }
    }  // function setValue

    function getValueToSave()
    {
        if(!isset($this->dbField))
        {
            $this->valueToSave = FALSE;
            return(TRUE);
        }
        if(array_key_exists($this->dbField.'_ERASE',$_POST))
        {
            $this->valueToSave = "";
        }
        else if(array_key_exists($this->dbField,$_FILES))
        {
            $this->valueToSave =
                file_get_contents($_FILES[$this->dbField]['tmp_name']);
            return(TRUE);

        } // if key exists
        else
        {
            $this->valueToSave = FALSE;
        }
    }  // function getValueToSave

    function formatOutput()
    // returns the HTML representation of this iInput
    {
        if($this->readOnly)
        {
            return('<img width="'.$this->ROwidth.'" src="'.$this->buildMyURL(
                array("deleteRec","currentRec","chkkey","where",
                        "PRIMARYKEYS","sheetView")).'FIFORMS_IFILE_DOWNLOAD=IMAGE&amp;FIFORMS_IFILE_FIELD='.$this->dbField.'&amp;PRIMARYKEYS='.$this->primaryKeyFilter.'" />');
        }
        else
        {
            return("<input type=\"$this->type\" name=\"$this->dbField\" ".
                " class=\"text\" $this->otherTags />".
                "<input name=\"MAX_FILE_SIZE\" value=\"$this->maxSize\" type=\"hidden\" /> ".
                "(Erase <input type=\"checkbox\" name=\"$this->dbField"."_ERASE\" /> )".
                (
                $this->showAsImage ? (
                "<br /><img src=\"".
                $this->buildMyURL(array()).
        "&FIFORMS_IFILE_DOWNLOAD=IMAGE&FIFORMS_IFILE_FIELD=$this->dbField\" alt=\"\" /> ")
                : ("<a href=\"".
                $this->buildMyURL(array()).
        "&FIFORMS_IFILE_DOWNLOAD=DOWNLOAD&FIFORMS_IFILE_FIELD=$this->dbField\">Download</a> ".$this->value)));
        }
    } // function outputRow

} // class iText

/* ?></code><?php */

?>
Return current item: FiForms Framework