Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > media > main > by-pkgid > 0afeee9cca140e167a996902b9a677c5 > files > 1259

php-manual-en-4.3.0-2mdk.noarch.rpm

<HTML
><HEAD
><TITLE
>is_uploaded_file</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="PHP Manual"
HREF="index.html"><LINK
REL="UP"
TITLE="Filesystem functions"
HREF="ref.filesystem.html"><LINK
REL="PREVIOUS"
TITLE="is_readable"
HREF="function.is-readable.html"><LINK
REL="NEXT"
TITLE="is_writable"
HREF="function.is-writable.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=ISO-8859-1"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.is-readable.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.is-writable.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.is-uploaded-file"
></A
>is_uploaded_file</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN26452"
></A
><P
>    (PHP 3&#62;= 3.0.17, PHP 4 &#62;= 4.0.3)</P
>is_uploaded_file&nbsp;--&nbsp;Tells whether the file was uploaded via HTTP POST</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN26455"
></A
><H2
>Description</H2
>bool <B
CLASS="methodname"
>is_uploaded_file</B
> ( string filename)<BR
></BR
><P
>&#13;     Returns <TT
CLASS="constant"
><B
>TRUE</B
></TT
> if the file named by <TT
CLASS="varname"
>filename</TT
> was
     uploaded via HTTP POST. This is useful to help ensure that a
     malicious user hasn't tried to trick the script into working on
     files upon which it should not be working--for instance,
     <TT
CLASS="filename"
>/etc/passwd</TT
>.
    </P
><P
>&#13;     This sort of check is especially important if there is any chance
     that anything done with uploaded files could reveal their
     contents to the user, or even to other users on the same
     system.
    </P
><P
>&#13;     <B
CLASS="function"
>is_uploaded_file()</B
> is available only in
     versions of PHP 3 after PHP 3.0.16, and in versions of PHP 4
     after 4.0.2. If you are stuck using an earlier version, you can
     use the following function to help protect yourself:
     <DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Note: </B
>
       The following example will <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>not</I
></SPAN
> work in
       versions of PHP 4 after 4.0.2. It depends on internal
       functionality of PHP which changed after that version.
      </P
></BLOCKQUOTE
></DIV
>
     <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php
/* Userland test for uploaded file. */
function is_uploaded_file($filename) {
    if (!$tmp_file = get_cfg_var('upload_tmp_dir')) {
        $tmp_file = dirname(tempnam('', ''));
    }
    $tmp_file .= '/' . basename($filename);
    /* User might have trailing slash in php.ini... */
    return (ereg_replace('/+', '/', $tmp_file) == $filename);
}

/* This is how to use it, since you also don't have
 * move_uploaded_file() in these older versions: */
if (is_uploaded_file($HTTP_POST_FILES['userfile'])) {
    copy($HTTP_POST_FILES['userfile'], "/place/to/put/uploaded/file");
} else {
    echo "Possible file upload attack: filename '$HTTP_POST_FILES[userfile]'.";
}
?&#62;</PRE
></TD
></TR
></TABLE
>
    </P
><P
>&#13;     See also <A
HREF="function.move-uploaded-file.html"
><B
CLASS="function"
>move_uploaded_file()</B
></A
>, and the section
     <A
HREF="features.file-upload.html"
>Handling file uploads</A
>
     for a simple usage example.
    </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.is-readable.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.is-writable.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>is_readable</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.filesystem.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>is_writable</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>