NYCPHP Meetup

NYPHP.org

[nycphp-talk] File Uploads

Elijah Insua tmpvar at gmail.com
Thu Jan 8 15:29:48 EST 2009


On Thu, Jan 8, 2009 at 3:23 PM, Michele Waldman <mmwaldman at nyc.rr.com>wrote:

>  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?
>
>
$_FILES should be available through out a request as it is a super global

>
> 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
>
You may want to make sure, but I'm quite positive that you cannot upload
files using 'AJAX', look to flash or an iframe if this is really important.

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


More information about the talk mailing list