Jump to content

eo92866

Members
  • Posts

    40
  • Joined

  • Last visited

    Never

Everything posted by eo92866

  1. thank you... for the excel portion... i think i'm just going to go with .csv... haven't had much success with that. and was thinking of inserting vbs code into php to convert the .xls into .csv and then run the foreach loop... finally inserting into sql. very nice round about process. and thank you.
  2. load into $handle. just kidding... i appreciate your assistance. the ultimate goal is to find the correlating matching file and have that .xls file have it's contents extracted and placed into a mysql table. but i don't want users to have to do any uploading of files... only select a file from a pull down menu that they want the .xls fields to be extracted and placed into mysql. so, how would i have the information be loaded to send into mysql. and i'm using mysql 5.0.45
  3. 1. load a file path 2. match only a file with the name US within the file path 3. and match only a file extension with .xls in that file path 4. load that match into fopen and $handle this is what i have so far: $files = array_diff (scandir("/my/file/path/") , array(".", "..") ); print_r($files); $filepathinfo = pathinfo($files); $extension = $filepathinfo['.xls']; echo basename($filepathinfo); $handle = fopen("$extension", "r");
  4. just mad a modification to the post. but i am trying to load a file by paring down the results with filepath, piece of file name and extension. then load the result into $handle. this would automate the loading of a file without having a user to do any kind of file uploading.
  5. hi... thank you for the responses... i read the info on php.net what i'm exactly trying to do is... load a directory /my/path/name and since there are multiple files with the same extension in that folder... i'd like to only search/return the first portion of the file name... essentially narrowing down the results of the differing files and load the variable/array and then into $handle. i've been trying to figure a way to use basename to implement this??? $handle will essentially load the file for a loop that i will run later. the thinking behind this is to automate the loading of files to later run a parser later. hope i explained better???
  6. i'd like to only obtain the file path and extension of a file... and then only utilize that information in $handle. [php $path = "/my/file/path/US_*.xls"; echo dirname($path); $pathinfo = pathinfo($path); $extension = $pathinfo['.xls']; echo basename($pathinfo); echo basename($extension); $handle = fopen("$extension", "r"); [/code] can someone please assist?
  7. the web page didn't display any errors or messages. executing the code via command line returned an error of: ./file.php: line 3: syntax error near unexpected token `'display_errors',' ./file.php: line 3: `ini_set('display_errors', 1);' finally, error_reporting is set to E_ALL and display_errors is set to Off in php.ini
  8. so i've come up with this... still not populating mysql. if someone can please assist. many thanks. <?php //connect to the database include "opendb.php"; #if the first row of csv file contains column headings: $columnheadings = 1; $i=0 $handle = fopen("/my/file/destination/name.csv", "r"); while ($i<10000) { //splitting data using fgetcsv and into array $data $data = fgetcsv($handle, 1000, ",") # echo "<p> $num fields in line $columnheadings: <br /></p>\n"; //mysql insert of values $sqlData = mysql_query("INSERT INTO thisTable(name1, name2, name3, name4, name5) VALUES('".$data[0]."', '".$data[1]."', '".$data[2]."', '".$data[3]."', '".$data[4]."')"); $i++ } fclose($handle); mysql_close($con); ?>
  9. not sure as to why it stops... i've added echo's a few times over and commented out at various points with no luck... so i'm turning here.
  10. my script doesn't get to the point of even displaying an error from mysql.
  11. the code below isn't populating the mysql fields... i believe it's not running correctly at the while and for loop areas. also, would like to know of a way to have the 1000 to have the ability to look at the end of the row and then look at the next row of data, because there are sometimes +/-1000 characters in a row. can someone please assist? many thanks. <?php //connect to the database include "opendb.php"; #if the first row of csv file contains column headings: $columnheadings = 1; if (($handle = fopen("/my/file/destination/name.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); # echo "<p> $num fields in line $columnheadings: <br /></p>\n"; $columnheadings++; for ($i=0; $i<$num; $i++) { $line = trim($data[$i],'",'); $arr = explode(',',$line); //mysql insert of values $sqlData = ("INSERT INTO thisTable(name1, name2, name3, name4, name5) VALUES('".$arr[0]."', '".$arr[1]."', '".$arr[2]."', '".$arr[3]."', '".$arr[4]."')"); } } fclose($handle); } else { mysql_query($sqlData) or die(mysql_error("The specified file does not exist. Thanks.")); } mysql_close($con); ?>
  12. i agree with PFMaBiSmAd... the link provided has a lot of information if you sit down and read all of it... but you want something fast... so... read the following links and you should get to where you'd like. http://php.net/manual/en/ref.simplexml.php this one will get you the tutorial that you are looking for http://www.ibm.com/developerworks/library/x-pullparsingphp.html
  13. i'm trying to output to a mysql db and to the screen, so a person can save the xml data. i'd like to save the entire xml document to the db, but only output certain elements to the screen. i was hoping to pair that information down utilizing the livesearch.php file. i'm not sure if that would be the ideal way??? finally, i believe i have the print to screen statement in the simple.php file. echo ('$xml'); does this help???
  14. thank you... the upload page now uploads the information... does the information go to a temporary directory? is there a way i can pair down the elements and child node element results from the xml document?
  15. hi, i'm trying to create simple form that will also upload only xml data. first, the user will need to upload an xml document only by clicking submit, the data will be posted to the server and the user will be redirected to uploader.php. This PHP file is going to process the form data and do all the work. #upload.php <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <body> <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="500" /> Please select the correct file that you require to create an XML export. <br/> <label for="uploadfile">Filename:</label> <input name="uploadfile" type="file" size="100"/> <input type="submit" value="Upload File" /> </form> </body> </html> second, i'd like to process the data and post the information to another php document that will parse the xml document. this particular file is not getting past the first if statement. i'm not really seeing why??? #uploader.php <?php //File upload restrictions parameters //Will only restrict to allowing xml documents to be uploaded if ((($_FILES["file"]["type"] == "application /xml") { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; //Save the uploaded files to a directory //If the file already exists with the same date stamp, do not upload if (file_exists("../upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } //If the file does not exist, create a new entry else { move_uploaded_file($_FILES["file"]["tmp_name"], "../upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "../upload/" . $_FILES["file"]["name"]; } } } //Create an error messag else { echo "This is an invalid file. Please make sure an XML document has been selected to upload. Thanks."; } // make an error handler which will be used if the upload fails function error($error, $location, $seconds = 20) { header("Refresh: $seconds; URL=\"$location\""); echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'."\n". '"http://www.w3.org/TR/html4/strict.dtd">'."\n\n". '<html lang="en">'."\n". ' <head>'."\n". ' <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">'."\n\n". ' <link rel="stylesheet" type="text/css" href="stylesheet.css">'."\n\n". ' <title>Upload error</title>'."\n\n". ' </head>'."\n\n". ' <body>'."\n\n". ' <div id="Upload">'."\n\n". ' <h1>Upload failure</h1>'."\n\n". ' <p>An error has occured: '."\n\n". ' <span class="red">' . $error . '...</span>'."\n\n". ' The upload form is reloading</p>'."\n\n". ' </div>'."\n\n". '</html>'; exit; } // end error handler ?> third, once the simple file parses the information.. i'd like to display a dropdown menu that will allow a person to select what entry they'd like to be displayed, namely page to be redirected to. #dropdown.php <?php $drop = $_REQUEST['dropdown']; ?> <html> <body> <form action="results.php" method="POST" name="links"> <select name="dropdown" value="options"> <option value"form.php">Select a Format</option> <option value="1.php">1</option> <option value="2.php">2</option> <option value="3.php">3</option> <option value="4.php">4</option> <option value="5.php">5</option> </select> <br/> <br/> <input type="submit" value="Submit Query"/> </body> </html> fourth part I, based on the above information... the user should have a page with a include("livesearch.php") for 1.php, but i will place livesearch.php code below... #livesearch.php $target_path = $target_path . basename($_FILES['uploadedfile']['tmp_name']); $xmlDoc=new DOMDocument(); $xmlDoc->load("uploader.ph"); $x=$xmlDoc->getElementsByTagName('link'); //get the q parameter from URL $q=$_GET["q"]; //lookup all links from the xml file if length of q>0 if (strlen($q)>0) { $hint=""; for($i=0; $i<($x->length); $i++) { $y=$x->item($i)->getElementsByTagName('PPC'); $z=$x->item($i)->getElementsByTagName('url'); if ($y->item(0)->nodeType==1) { //find a link matching the search text if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q)) { if ($hint=="") { $hint="<a href='" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . "</a>"; } else { $hint=$hint . "<br /><a href='" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . "</a>"; } } } } } // Set output to "no suggestion" if no hint were found // or to the correct values if ($hint=="") { $response="no suggestion"; } else { $response=$hint; } //output the response echo $response; ?> fourth part II, the above code will be part of 1.php... this part of the form will ideally return a livesearch query from the uploaded xml document for the checked boxes by an element's name. #form.php <html> <head> <script type="text/javascript"> function showResult(str) { if (str.length==0) { document.getElementById("livesearch").innerHTML=""; document.getElementById("livesearch").style.border="0px"; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("livesearch").innerHTML=xmlhttp.responseText; document.getElementById("livesearch").style.border="1px solid #A5ACB2"; } } xmlhttp.open("GET","livesearch.php?q="+str,true); xmlhttp.send(); } </script> </head> <body> <?php echo "<form> Please place element1 # to search: <input type='text' size='30' onkeyup='showResult(this.value)' /> <div id='livesearch'></div> </form>"; // This is to collect box array value as global_variables is set off in PHP5 by default // // variable that will send $box information from the checkboxes named getXMLbox to // an variable array $box=$_POST['getXMLbox']; if(empty($box)) { echo("These are the boxes that WERE not selected: $box"); } else { $N = count($box); echo("These are the boxes that ARE selected: $N "); for($i=0; $i<$N; $i++) { echo($box[$i] . " "); } } while (list ($key,$val) = @each ($box)) { echo "$val,"; } echo "<form method=post action='simple.php'>"; echo "<table border='0' cellspacing='0' style='border-collapse: collapse' width='100' > <tr bgcolor='#ffffff'> <td width='25%'><input type=checkbox name=getXMLbox[] value='element1'></td> <td width='25%'> element1</td> </tr> <tr bgcolor='#ffffff'> <td width='25%'><input type=checkbox name=getXMLbox[] value='element2'></td> <td width='25%'> element2</td> </tr> <tr> <td><br/></td> </tr> <tr> <td colspan =6 align=center><input type=submit name=SubmitForm value='Submit Query'></form></td> </tr> </table>"; ?> finally, i'd like to parse the data with a php5 function and display the xml information onto the screeen or have a dialog box open up for a person to save as. #simple.php <?php /* we will use simpleXML to transfer xml data to parse and read xml data */ //load the xml file to $file $file = ($_FILES["file"]["name"]); #load xml data $xml = simplexml_load_file($file) or die ("The connection to could not load the XML document. Please try again. \n"); #display the entire document echo ('$xml'); ?> so basically, i'm a bit lost and not getting the right outcome that i'd like. can someone please assist? many thanks.
×
×
  • 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.