[nycphp-talk] File Uploads
Artur Marnik
artur at marnik.net
Mon Jan 12 11:44:46 EST 2009
put $_FILES into the session before you do the ajax request
$_SESSION['uploaded_files'] = $_FILES;
and use $_SESSION['uploaded_files'] in your ascript.php
Artur
Michele Waldman 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?
>
>
>
> 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
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> New York PHP User Group Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> http://www.nyphp.org/show_participation.php
More information about the talk
mailing list