Jump to content

how to retrieve uploaded file


mpsn

Recommended Posts

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!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.