ricmetal Posted May 23, 2010 Share Posted May 23, 2010 hi guys can someone tell me what the hell that name means please and how to access it? <input type="file" class="upload" name="fileX[]" /> Quote Link to comment Share on other sites More sharing options...
ignace Posted May 23, 2010 Share Posted May 23, 2010 The name represents an array in PHP and can be accessed as $_GET['fileX'] or $_POST['fileX'] Quote Link to comment Share on other sites More sharing options...
ricmetal Posted May 23, 2010 Author Share Posted May 23, 2010 thanks Quote Link to comment Share on other sites More sharing options...
ricmetal Posted May 23, 2010 Author Share Posted May 23, 2010 hi im accessing it as i would any other POST variable but i'm not getting any outpution what's happening is that im building a multifile upload thing and for each file i select, i hide the file input element and add another one in the same place to look like it's always the same one. i'm give it the name (its not me - following a tut and tweaking). the new name for each input is name="fileArray[]" what does this code do? does it automatically create fileArray[0] = "name of the file selected"; ? i've tried outputting $_POST[fileArray[0]]; with no success :/ Quote Link to comment Share on other sites More sharing options...
F1Fan Posted May 24, 2010 Share Posted May 24, 2010 You have your brackets in the wrong place: $_POST['fileArray'][0]; If all else fails, do this to see what you're getting: print_r($_POST); Quote Link to comment Share on other sites More sharing options...
ricmetal Posted May 24, 2010 Author Share Posted May 24, 2010 there seems to be a bug in php or html google "empty post php" the only thing i was able to change and get my code to work was changing from enctype="multipart/form-data" to "multipart/mixed" else print_r($_POST); always retunred empty Quote Link to comment Share on other sites More sharing options...
F1Fan Posted May 24, 2010 Share Posted May 24, 2010 Post your code. Quote Link to comment Share on other sites More sharing options...
ricmetal Posted May 24, 2010 Author Share Posted May 24, 2010 <?php session_start(); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html><head><title>title</title> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" > <meta http-equiv="Expires" content="0"> <link href="../css/panel.css" rel="stylesheet" type="text/css"> <link href="../css/photos.css" rel="stylesheet" type="text/css"> </head> <body> <div id="wrapper"> <? include 'phpincludes/menu.php' ?> <div id="sectionTitleDiv">Photos</div> <form name="uploadForm" method="post" enctype="multipart/form-data"> <table id="mainTable" cellspacing="0" cellpadding="0"><tr> <td id="selectorTd" valign="top"> <div id="fileSpecs">Allowed extension: <b>jpg</b><br />Max file size: <b>250Kb</b><br />Max image dimensions: <b>100px</b>(width),<b>150px</b>(height)<br/>Max images: <b>30</b></div> <div> <input type="file" name="fileArray" id="inputElement"/> </div> </td> <td id="galleryTd" valign="top"><?php print_r($_POST); ?></td></tr> <tr><td colspan="2" class="footer"><input type="submit" value="Save"/></td></tr> </table> </form> </div> </div> </body> </html> edit: that doesn0t even work, without an array. i simplified for simplification edit2:i kept out the javascript to hide the input field and replace it with another one. using jquery. i dont think it's relevant, cause with that code simply changing to form-data breaks the post anyway Quote Link to comment Share on other sites More sharing options...
ricmetal Posted May 24, 2010 Author Share Posted May 24, 2010 you guys sure you can access the file using $_POST using form enctype=multipart/form-data? Quote Link to comment Share on other sites More sharing options...
ignace Posted May 24, 2010 Share Posted May 24, 2010 Yes this works on every element: <input type="checkbox" name="checked[]"> <input type="checkbox" name="checked[]"> <input type="checkbox" name="checked[]"> <input type="checkbox" name="checked[]"> <input type="checkbox" name="checked[]"> <input type="checkbox" name="checked[]"> <input type="checkbox" name="checked[]"> <input type="checkbox" name="checked[]"> <input type="checkbox" name="checked[]"> print_r($_POST['checked']);//returns an array of all those which are checked. Quote Link to comment Share on other sites More sharing options...
ricmetal Posted May 24, 2010 Author Share Posted May 24, 2010 well, this does not work <form name="uploadForm" method="post" enctype="multipart/form-data"> <input type="file" name="fileToUpload"/><br/> <?php print_r($_POST['fileToUpload']); ?><br> <input type="submit" value="Save"/> </form> ...so im guessing either u cannot call a file directly through post, or there's a bug with the enctype Quote Link to comment Share on other sites More sharing options...
ignace Posted May 24, 2010 Share Posted May 24, 2010 well, this does not work That's because it's $_FILE['fileToUpload'], I possibly forgot to mention that for uploads a different global was used. Quote Link to comment Share on other sites More sharing options...
F1Fan Posted May 24, 2010 Share Posted May 24, 2010 Here's a quick little tutorial that may help: http://www.w3schools.com/php/php_file_upload.asp Quote Link to comment Share on other sites More sharing options...
ricmetal Posted May 24, 2010 Author Share Posted May 24, 2010 i know abuot $_FILES i was asking about $_POST because you guys mentioned $_POST continuously. Quote Link to comment Share on other sites More sharing options...
F1Fan Posted May 24, 2010 Share Posted May 24, 2010 ignace and I were both overlooking the fact that you had an input type of "file." If you have a form with enctype="multipart/form-data", then the file type is $_FILE and all other inputs are still $_POST. So, to correct my first post: $_FILE['fileArray'][0]; Quote Link to comment Share on other sites More sharing options...
ricmetal Posted May 24, 2010 Author Share Posted May 24, 2010 yep thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.