473,320 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Opening file from folder.

Hi,
I an tryin to create a html page where users can choose a file and open it however, i keep getting it wrong.So far this is wat i've worked on:
(open.html)
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Opening file</title>
  4. </head>
  5. <body>
  6. <form  action="display.php" method="POST">
  7. Please choose a file: <input name="saved" type="file" /><br />
  8. <input type="submit" value="Open" />
  9. </form> 
  10. </body>
  11. </html>
and the php codes are:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $target = "upload/"; 
  3. $target = $target . basename( $_FILES['saved']['name']) ; 
  4. $ok=1;
  5.  
  6. if (!($fp=@fopen(basename($_FILES['saved']['name']), "r"))) die ("Couldn't open XML.");
  7. $usercount=0;
  8. $userdata=array();
  9. $state='';
  10.  
  11. function startElementHandler ($parser,$name,$attrib){
  12. global $usercount;
  13. global $userdata;
  14. global $state;
  15.  
  16. switch ($name) {
  17. case $name=="NAME" : {
  18. $userdata[$usercount]["first"] = $attrib["FIRST"];
  19. $userdata[$usercount]["last"] = $attrib["LAST"];
  20. $userdata[$usercount]["nick"] = $attrib["NICK"];
  21. $userdata[$usercount]["title"] = $attrib["TITLE"];
  22. break;
  23. }
  24. case $name=="STREET" : {
  25. $userdata[$usercount]["hstreet"] = $attrib["HOME"];
  26. $userdata[$usercount]["bstreet"] = $attrib["WORK"];
  27. break;
  28. }
  29. case $name=="CITY" : {
  30. $userdata[$usercount]["hcity"] = $attrib["HOME"];
  31. $userdata[$usercount]["bcity"] = $attrib["WORK"];
  32. break;
  33. }
  34. case $name=="COUNTY" : {
  35. $userdata[$usercount]["hcounty"] = $attrib["HOME"];
  36. $userdata[$usercount]["bcounty"] = $attrib["WORK"];
  37. break;
  38. }
  39. case $name=="POSTAL" : {
  40. $userdata[$usercount]["hpostal"] = $attrib["HOME"];
  41. $userdata[$usercount]["bpostal"] = $attrib["WORK"];
  42. break;
  43. }
  44. case $name=="COUNTRY" : {
  45. $userdata[$usercount]["hcountry"] = $attrib["HOME"];
  46. $userdata[$usercount]["bcountry"] = $attrib["WORK"];
  47. break;
  48. }
  49. case $name=="PHONE" : {
  50. $userdata[$usercount]["hphone"] = $attrib["HOME"];
  51. $userdata[$usercount]["bphone"] = $attrib["WORK"];
  52. break;
  53. }
  54. case $name=="FAX" : {
  55. $userdata[$usercount]["hfax"] = $attrib["HOME"];
  56. $userdata[$usercount]["bfax"] = $attrib["WORK"];
  57. break;
  58. }
  59. case $name=="MOBILE" : {
  60. $userdata[$usercount]["hmobile"] = $attrib["HOME"];
  61. $userdata[$usercount]["bmobile"] = $attrib["WORK"];
  62. break;
  63. }
  64. case $name=="WEB" : {
  65. $userdata[$usercount]["hweb"] = $attrib["HOME"];
  66. $userdata[$usercount]["bweb"] = $attrib["WORK"];
  67. break;
  68. }
  69.  
  70. default : {$state=$name;break;}
  71. }
  72. }
  73.  
  74. function endElementHandler ($parser,$name){
  75. global $usercount;
  76. global $userdata;
  77. global $state;
  78. $state='';
  79. if($name=="CONTACT") {$usercount++;}
  80. }
  81.  
  82. function characterDataHandler ($parser, $data) {
  83. global $usercount;
  84. global $userdata;
  85. global $state;
  86. if (!$state) {return;}
  87. if ($state=="COMPANY") { $userdata[$usercount]["bcompany"] = $data;}
  88. if ($state=="GENDER") { $userdata[$usercount]["gender"] = $data;}
  89. if ($state=="BDAY") { $userdata[$usercount]["bday"] = $data;}
  90. if ($state=="ANNI") { $userdata[$usercount]["anni"] = $data;}
  91. if ($state=="SPOUSE") { $userdata[$usercount]["spouse"] = $data;}
  92. if ($state=="CHILDREN") { $userdata[$usercount]["children"] = $data;}
  93. if ($state=="EMAILONE") { $userdata[$usercount]["email1"] = $data;}
  94. if ($state=="EMAILTWO") { $userdata[$usercount]["email2"] = $data;}
  95. if ($state=="EMAILTHREE") { $userdata[$usercount]["email3"] = $data;}
  96. if ($state=="EMAILFOUR") { $userdata[$usercount]["email4"] = $data;}
  97. if ($state=="COMMENT") {$userdata[$usercount]["comment"] = $data;}
  98. }
  99. if (!($xml_parser = xml_parser_create())) die("Couldn't create parser.");
  100. xml_set_element_handler( $xml_parser, "startElementHandler", "endElementHandler");
  101. xml_set_character_data_handler( $xml_parser, "characterDataHandler");
  102.  
  103. while( $data = fread($fp, 4096)){
  104. if(!xml_parse($xml_parser, $data, feof($fp))) {
  105. break;}}
  106. xml_parser_free($xml_parser);
  107.  
  108. ?>
  109. <html>
  110. <head><title>CodeHelp - Testing PHP XML parser</title>
  111. </head>
  112. <body>
  113. <?php
  114. for ($i=0;$i<$usercount; $i++)
  115. {
  116.         echo "Name: ".$userdata[$i]["title"]." ".ucfirst($userdata[$i]["first"])." ". ucfirst($userdata[$i]["last"])."<br>";
  117.  
  118.  
  119.      if ($userdata[$i]["nick"]) {echo "Nickname ".$userdata[$i]["nick"]."<br>";}
  120.  
  121.         if ($userdata[$i]["hstreet"]) {
  122.                 echo "Home Address: ".$userdata[$i]["hstreet"].", ";
  123.                 echo $userdata[$i]["hcity"].", ".$userdata[$i]["hcounty"].", ". $userdata[$i]["hpostal"].
  124.                         ". ".$userdata[$i]["hcountry"]."<br>";
  125.         }
  126.  
  127.         if ($userdata[$i]["hphone"]) {echo "Home Phone ".$userdata[$i]["hphone"]."<br>";}
  128.         if ($userdata[$i]["hfax"]) {echo "Home Fax ".$userdata[$i]["hfax"]."<br>";}
  129.         if ($userdata[$i]["hmobile"]) {echo "Personal Mobile ".$userdata[$i]["hmobile"]."<br>";}
  130.         if ($userdata[$i]["hweb"]) {
  131.                 echo "Personal site: <a href=\"".$userdata[$i]["hweb"]."\">".$userdata[$i]["hweb"]."</a><br>";
  132.         }
  133.  
  134.         if ($userdata[$i]["bstreet"]) {
  135.                 echo "Business Address: ".$userdata[$i]["bstreet"];
  136.                 echo ", ".$userdata[$i]["bcity"].". ".$userdata[$i]["bcounty"].", ". $userdata[$i]["bpostal"].
  137.                         ". ".$userdata[$i]["bcountry"]."<br>";
  138.         }
  139.  
  140.         if ($userdata[$i]["bphone"]) {echo "Work Phone ".$userdata[$i]["bphone"]."<br>";}
  141.         if ($userdata[$i]["bfax"]) {echo "Work Fax ".$userdata[$i]["bfax"]."<br>";}
  142.         if ($userdata[$i]["bmobile"]) {echo "Business Mobile ".$userdata[$i]["bmobile"]."<br>";}
  143.         if ($userdata[$i]["bcompany"]) {echo "Company: ".$userdata[$i]["bcompany"]."<br>";}
  144.         if ($userdata[$i]["gender"]) {echo "Gender: ".$userdata[$i]["gender"]."<br>";}
  145.         if ($userdata[$i]["children"]) {echo "Children: ".$userdata[$i]["children"]."<br>";}
  146.         if ($userdata[$i]["bday"]) {echo "Birthday: ".$userdata[$i]["bday"]."<br>";}
  147.         if ($userdata[$i]["anni"]) {echo "Anniversary: ".$userdata[$i]["anni"]."<br>";}
  148.         if ($userdata[$i]["spouse"]) {echo "Spouse: ".$userdata[$i]["spouse"]."<br>";}
  149.         if ($userdata[$i]["bweb"]) {
  150.                 echo "Business site: <a href=\"".$userdata[$i]["bweb"]."\">".$userdata[$i]["bweb"]."</a><br>";
  151.         }
  152.  
  153.         if ($userdata[$i]["email1"]) {
  154.                 echo "email: <a href=\"mailto:".$userdata[$i]["email1"]."\">".$userdata[$i]["email1"]."</a><br>";
  155.                 if ($userdata[$i]["email2"]) {
  156.                         echo "email: <a href=\"mailto:".$userdata[$i]["email2"]."\">".$userdata[$i]["email2"]."</a><br>";
  157.                         if ($userdata[$i]["email3"]) {
  158.                                 echo "email: <a href=\"mailto:".$userdata[$i]["email3"]."\">".$userdata[$i]["email3"]."</a><br>";
  159.                                 if ($userdata[$i]["email4"]) {
  160.                                         echo "email: <a href=\"mailto:".$userdata[$i]["email4"]."\">".$userdata[$i]["email4"]."</a><br>";
  161.                                 }
  162.                         }
  163.                 }
  164.         }
  165.  
  166.         if ($userdata[$i]["comment"]) {echo "<tr><td colspan=2>Notes: ".$userdata[$i]["comment"]."</td></tr>\n";}
  167.  if ($userdata[$i]["title"]!=null){
  168.  echo "Data type for title = char";
  169.  }
  170.  
  171.  
  172. ?>
  173. </table>
  174.  
  175.  
  176. </body><html>
Hope someone can help.
Aug 10 '07 #1
5 1956
munnaj
6
Hi,
I an tryin to create a html page where users can choose a file and open it however, i keep getting it wrong.So far this is wat i've worked on:
(open.html)
<html>
<head>
<title>Opening file</title>
</head>
<body>
<form action="display.php" method="POST">
Please choose a file: <input name="saved" type="file" /><br />
<input type="submit" value="Open" />
</form>
</body>
</html>

and the php codes are:

<?php
$target = "upload/";
$target = $target . basename( $_FILES['saved']['name']) ;
$ok=1;

if (!($fp=@fopen(basename($_FILES['saved']['name']), "r"))) die ("Couldn't open XML.");
$usercount=0;
$userdata=array();
$state='';

function startElementHandler ($parser,$name,$attrib){
global $usercount;
global $userdata;
global $state;

switch ($name) {
case $name=="NAME" : {
$userdata[$usercount]["first"] = $attrib["FIRST"];
$userdata[$usercount]["last"] = $attrib["LAST"];
$userdata[$usercount]["nick"] = $attrib["NICK"];
$userdata[$usercount]["title"] = $attrib["TITLE"];
break;
}
case $name=="STREET" : {
$userdata[$usercount]["hstreet"] = $attrib["HOME"];
$userdata[$usercount]["bstreet"] = $attrib["WORK"];
break;
}
case $name=="CITY" : {
$userdata[$usercount]["hcity"] = $attrib["HOME"];
$userdata[$usercount]["bcity"] = $attrib["WORK"];
break;
}
case $name=="COUNTY" : {
$userdata[$usercount]["hcounty"] = $attrib["HOME"];
$userdata[$usercount]["bcounty"] = $attrib["WORK"];
break;
}
case $name=="POSTAL" : {
$userdata[$usercount]["hpostal"] = $attrib["HOME"];
$userdata[$usercount]["bpostal"] = $attrib["WORK"];
break;
}
case $name=="COUNTRY" : {
$userdata[$usercount]["hcountry"] = $attrib["HOME"];
$userdata[$usercount]["bcountry"] = $attrib["WORK"];
break;
}
case $name=="PHONE" : {
$userdata[$usercount]["hphone"] = $attrib["HOME"];
$userdata[$usercount]["bphone"] = $attrib["WORK"];
break;
}
case $name=="FAX" : {
$userdata[$usercount]["hfax"] = $attrib["HOME"];
$userdata[$usercount]["bfax"] = $attrib["WORK"];
break;
}
case $name=="MOBILE" : {
$userdata[$usercount]["hmobile"] = $attrib["HOME"];
$userdata[$usercount]["bmobile"] = $attrib["WORK"];
break;
}
case $name=="WEB" : {
$userdata[$usercount]["hweb"] = $attrib["HOME"];
$userdata[$usercount]["bweb"] = $attrib["WORK"];
break;
}

default : {$state=$name;break;}
}
}

function endElementHandler ($parser,$name){
global $usercount;
global $userdata;
global $state;
$state='';
if($name=="CONTACT") {$usercount++;}
}

function characterDataHandler ($parser, $data) {
global $usercount;
global $userdata;
global $state;
if (!$state) {return;}
if ($state=="COMPANY") { $userdata[$usercount]["bcompany"] = $data;}
if ($state=="GENDER") { $userdata[$usercount]["gender"] = $data;}
if ($state=="BDAY") { $userdata[$usercount]["bday"] = $data;}
if ($state=="ANNI") { $userdata[$usercount]["anni"] = $data;}
if ($state=="SPOUSE") { $userdata[$usercount]["spouse"] = $data;}
if ($state=="CHILDREN") { $userdata[$usercount]["children"] = $data;}
if ($state=="EMAILONE") { $userdata[$usercount]["email1"] = $data;}
if ($state=="EMAILTWO") { $userdata[$usercount]["email2"] = $data;}
if ($state=="EMAILTHREE") { $userdata[$usercount]["email3"] = $data;}
if ($state=="EMAILFOUR") { $userdata[$usercount]["email4"] = $data;}
if ($state=="COMMENT") {$userdata[$usercount]["comment"] = $data;}
}
if (!($xml_parser = xml_parser_create())) die("Couldn't create parser.");
xml_set_element_handler( $xml_parser, "startElementHandler", "endElementHandler");
xml_set_character_data_handler( $xml_parser, "characterDataHandler");

while( $data = fread($fp, 4096)){
if(!xml_parse($xml_parser, $data, feof($fp))) {
break;}}
xml_parser_free($xml_parser);

?>
<html>
<head><title>CodeHelp - Testing PHP XML parser</title>
</head>
<body>
<?php
for ($i=0;$i<$usercount; $i++)
{
echo "Name: ".$userdata[$i]["title"]." ".ucfirst($userdata[$i]["first"])." ". ucfirst($userdata[$i]["last"])."<br>";


if ($userdata[$i]["nick"]) {echo "Nickname ".$userdata[$i]["nick"]."<br>";}

if ($userdata[$i]["hstreet"]) {
echo "Home Address: ".$userdata[$i]["hstreet"].", ";
echo $userdata[$i]["hcity"].", ".$userdata[$i]["hcounty"].", ". $userdata[$i]["hpostal"].
". ".$userdata[$i]["hcountry"]."<br>";
}

if ($userdata[$i]["hphone"]) {echo "Home Phone ".$userdata[$i]["hphone"]."<br>";}
if ($userdata[$i]["hfax"]) {echo "Home Fax ".$userdata[$i]["hfax"]."<br>";}
if ($userdata[$i]["hmobile"]) {echo "Personal Mobile ".$userdata[$i]["hmobile"]."<br>";}
if ($userdata[$i]["hweb"]) {
echo "Personal site: <a href=\"".$userdata[$i]["hweb"]."\">".$userdata[$i]["hweb"]."</a><br>";
}

if ($userdata[$i]["bstreet"]) {
echo "Business Address: ".$userdata[$i]["bstreet"];
echo ", ".$userdata[$i]["bcity"].". ".$userdata[$i]["bcounty"].", ". $userdata[$i]["bpostal"].
". ".$userdata[$i]["bcountry"]."<br>";
}

if ($userdata[$i]["bphone"]) {echo "Work Phone ".$userdata[$i]["bphone"]."<br>";}
if ($userdata[$i]["bfax"]) {echo "Work Fax ".$userdata[$i]["bfax"]."<br>";}
if ($userdata[$i]["bmobile"]) {echo "Business Mobile ".$userdata[$i]["bmobile"]."<br>";}
if ($userdata[$i]["bcompany"]) {echo "Company: ".$userdata[$i]["bcompany"]."<br>";}
if ($userdata[$i]["gender"]) {echo "Gender: ".$userdata[$i]["gender"]."<br>";}
if ($userdata[$i]["children"]) {echo "Children: ".$userdata[$i]["children"]."<br>";}
if ($userdata[$i]["bday"]) {echo "Birthday: ".$userdata[$i]["bday"]."<br>";}
if ($userdata[$i]["anni"]) {echo "Anniversary: ".$userdata[$i]["anni"]."<br>";}
if ($userdata[$i]["spouse"]) {echo "Spouse: ".$userdata[$i]["spouse"]."<br>";}
if ($userdata[$i]["bweb"]) {
echo "Business site: <a href=\"".$userdata[$i]["bweb"]."\">".$userdata[$i]["bweb"]."</a><br>";
}

if ($userdata[$i]["email1"]) {
echo "email: <a href=\"mailto:".$userdata[$i]["email1"]."\">".$userdata[$i]["email1"]."</a><br>";
if ($userdata[$i]["email2"]) {
echo "email: <a href=\"mailto:".$userdata[$i]["email2"]."\">".$userdata[$i]["email2"]."</a><br>";
if ($userdata[$i]["email3"]) {
echo "email: <a href=\"mailto:".$userdata[$i]["email3"]."\">".$userdata[$i]["email3"]."</a><br>";
if ($userdata[$i]["email4"]) {
echo "email: <a href=\"mailto:".$userdata[$i]["email4"]."\">".$userdata[$i]["email4"]."</a><br>";
}
}
}
}

if ($userdata[$i]["comment"]) {echo "<tr><td colspan=2>Notes: ".$userdata[$i]["comment"]."</td></tr>\n";}
}
if ($userdata[$i]["title"]!=null){
echo "Data type for title = char";
}


?>
</table>


</body><html>

Hope someone can help.
=============================

hai,

Juz try this...... hope it works
Expand|Select|Wrap|Line Numbers
  1. <form  action="display.php" method="POST" enctype="multipart/form-data">
Aug 10 '07 #2
I know my error is at the php file.....its not a the html file....i believe the value "saved" is not passed on to the php file or may be the value is passed on but the php file does not grab it....
Aug 10 '07 #3
pbmods
5,821 Expert 4TB
Heya, bimeldip.

Please try to avoid posting so much code; you're more likely to get a response if you only post relevant snippets.

What do you want your code to do? Give an example.
What is your code doing that you don't want it to do? Give an example.
What is your code *not* doing that it is supposed to? Give an example.
Aug 13 '07 #4
pbmods
5,821 Expert 4TB
bimeldip and munnaj, please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.
Aug 13 '07 #5
Hi,
so sorry ...i did not realize that it wasn't allowed.I will keep in mind the next time.
My problem is that i want to develop a php class that has these functions:

1)Upload function
-users can browse for an xml file and click a button and upload it into a folder.

2)Recognize function
-from the file there is a function that will recognize the data type of the content of the file eg:
..
<FirstName>Tom</FirstName>
So it would recognize that Tom is a character so it will display the data type.

3)Import Function
-this function would be recognize the the fields in the xml file, and create a table based on the fields and import the data into the table in the mysql database.

so far i have only managed to learn how to upload the file into a folder.
But the problem is that i have hard code the xml file in my codes for it to display the content of the xml file.
eg:
..
if (!($fp=@fopen("upload/contactsbare.xml", "r"))) die ("Couldn't open XML.");
..
So i want to make it dynamic enough to pick any xml file that users will choose and is able to display it to the user.
How do i do this?

Please do help...
Aug 13 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Bob Murdoch | last post by:
I've got an intranet application that presents a list of files in sort of a 'central repository' web page. Each file is an href in the form <a href=file://server/share/path/filename.ext>. When...
2
by: Eric Caron | last post by:
Hi Here's my problem, I create a windows service with Config.xml file. All setup for my service is in this file. I create a windows application to manage these settings (Config.XML File). This...
3
by: Giuseppe D'Elia | last post by:
Hi there, I got a problem using an MS Access database through ASP.NET. After updating my system from .NET Framework 1.0 to 1.1, my existing application gives me the following error when...
1
by: Jennifer | last post by:
A long while back I made an ASP.Net application with VB.Net as the code behind. It's been in MS Source Safe. I now have a new computer and got the latest version downloaded from Source Safe on my...
1
by: Ddraig | last post by:
Howdy, I was wondering if anyone could point me in the direction of some good code that will look at a folder of various text files, read in the names and then open them. For example opening...
18
by: mollyf | last post by:
I just installed SQL Server 2005 on my PC (the developer's edition) yesterday. I have some scripts written by one of my coworkers to create some tables and stored procedures in a database that...
2
by: Jl_G_0 | last post by:
Hey all. Got a weird problem here. I need to open a folder that is on a server. The asp.net page and the IIS are on the same server. But i Cant access it from nowhere but locally. Simply because...
9
by: Raj | last post by:
Following is a code to open a file & print its contents on screen. But im getting the message "file can't be opened". The thing is, that if i create a file separately in a particular folder in C...
0
by: veer | last post by:
Hi i have a probleum in opening the access database which is on my LAN Networking with DAO. It is connecting and dispalaying the database name but when i use to open it, error displayed named"...
10
by: kimiraikkonen | last post by:
Hi, I have an app which has a listbox and when i double click an associated fileS, i want their paths to be added into listbox in my application. This code works good when i try to open a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.