mpsn Posted November 3, 2011 Share Posted November 3, 2011 Hi, I want to be able to let user upload XML form, and then in the action page it needs to extract that so that I can add it to the database. Here is the upload form: <html> <head></head> <body> <form method='post' action="uploadFileToDB.php" enctype="multipart/form-data"> <p> <label> Upload image<input type='file' name='imageFileType' id='imageFileType' /> </label> </p> <p> <input type='submit' value='Upload this image' name='upload' id='upload' /> </p> </form> </body> </html> Here is the uploadFileToDB.php: <?php require("PHP_xml_parsing_via_DOM.php"); //NB: this script does the actual shreddering (XML to SQL) //IF User uploaded dir or XML file successful, then: if(isset($_POST['upload'])) { //SHRED NOW //NB: how to retrieve the uploaded xml file $_filePath=?? $node=basename($_filePath); $dom=new DOMDocument(); $dom->load($node); $labelPath=array(); mysql_connect("localhost","root"); mysql_select_db("dummydpev7"); $isXdocExist=mysql_query("SELECT file_Path,file_Name FROM xdocument WHERE file_Path='$_filePath' AND file_Name='$node'"); $docId=0; if(mysql_num_rows($isXdocExist)==1) { print "Entry already exists!"; $docId=mysql_next_id("xdocument")-1; } else { mysql_query("INSERT INTO xdocument (file_Path,file_Name) VALUES ('$_filePath','$node')"); $docId=mysql_next_id("xdocument")-1; } print "<br />".$docId; writeXMLtoDBViaDOM($dom->documentElement,$labelPath,$docId,$_filePath); } //ELSE else //Please upload Valid XML print "Problem with XML file being uploaded."; ?> The question in point is how do I extract the file I uploaded to set to $_filePath?? in the script so that I pass it to my function writeXMLtoDBviaDOM?? Please any help much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/250344-how-to-retrieve-uploaded-file/ Share on other sites More sharing options...
mpsn Posted November 3, 2011 Author Share Posted November 3, 2011 Solved it, it's just $node=$_FILES['file']['name']; so I actually just wanted to get the xml file name and extension (so I changed $_filePath to just $node) BUT now I want to store the file path to a new variable $_filePath that I will pass to the function: writeXMltoDBviaDOM, so how do I do this? Any help much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/250344-how-to-retrieve-uploaded-file/#findComment-1284488 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.