NYCPHP Meetup

NYPHP.org

[nycphp-talk] File Uploads

Michele Waldman mmwaldman at nyc.rr.com
Thu Jan 8 15:23:40 EST 2009


form action="test.php" method="post" enctype="multipart/form-data">

<p>Pictures:

<input type="file" name="pictures[]" />

<input type="file" name="pictures[]" />

<input type="file" name="pictures[]" />

<input type="submit" value="Send" />

</p>

</form>

<?php
foreach ($_FILES["pictures"]["error"] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
        $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
        $name = $_FILES["pictures"]["name"][$key];
        move_uploaded_file($tmp_name, "data/$name");
    }
}
?> 

When test.php is called $_FILES is defined.  But, if I call another php
module right after $_FILES is no longer defined.  Is there a way to capture
the value of $_FILES or make it persist?

 

What I was trying was something like this:

form action="afunction();" method="post" enctype="multipart/form-data">

<p>Pictures:

<input type="file" name="pictures[]" />

<input type="file" name="pictures[]" />

<input type="file" name="pictures[]" />

<input type="submit" value="Send" />

</p>

</form>

function a_function()

{

 

       rlxmlHttp=getXmlHttpObject();

       if (rlxmlHttp == null)

       {

           document.getElementById("fnErrMsg").innerHTML = '*Browser does
not support HTTP Request';

       }

       else

       {

           rlxmlHttp.onreadystatechange=finishContact;

           rlxmlHttp.open("POST","ascript.php",true); /* ascript.php using
$_FILES */

           rlxmlHttp.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');

/*         rlxmlHttp.setRequestHeader('Content-Type',
'multipart/form-data'); */

           rlxmlHttp.send(null);

      }

}

The $_FILES variable no longer exist.  But, $_FILES is no longer defined.
Does anyone have any creative ideas?

Michele

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20090108/8f422ecc/attachment.html>


More information about the talk mailing list