PHP - Newb: Table Merge Issues
Hi there,
I'm new to this (2 days into it) but I've managed to rummage together 2 tables, and PHP to input into the database. My issue now is that I want to merge one of the two tables into the other. I've managed to do this, but for some reason I'm getting duplicate entries from the 2nd table. Code: //mysql connection $query = "SELECT ArticleDescription, URL FROM top_web_articles"or die ("query is messed up"); $result = mysql_query($query); while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { mysql_query("INSERT INTO web_articles (ArticleDescription, URL) SELECT ArticleDescription, URL FROM top_web_articles") or die ("Failed merge!"); } echo ("Successful merge!"); ?> Does anyone have any suggestions as to where I went wrong? Thanks in advance, Doofy. Similar TutorialsHi all, a have a small problem with my search script. At the moment I am searching a field in my tabel called searchtags, now if I enter a one word search term of a string of characters it will return the results but if they are not in the same order it won't. Example: searchtags contains - Ford Mondeo 1999 2.0L petrol car If I search "Ford Mondeo" the query returns results, whereas if I search "Mondeo Ford" the query returns no results? I assume I have to expand the search in some way but I don;t know how, any ideas? Thanks in advance Code: [Select] <?php // Get the search variable from URL $var = @$_GET['q'] ; $field = @$_GET['field'] ; $trimmed = trim($var); //trim whitespace from the stored variable if ($field == "") { //if search from homepage start here $query = "select * from fleet where searchtags like \"%$trimmed%\" order by fleetref"; // EDIT HERE and specify your table and field names for the SQL query $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); $limit=10000; if ($numrows == 0) { echo "<p>Sorry, your search: "" . $trimmed . "" motorhomes to hire returned zero results</p>"; } // next determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } // get results $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); // display what the person searched for echo "<h1>You searched for - " . $var . "cars</h1>"; // now you can display the results returned while ($row= mysql_fetch_array($result)) { $fleetref = $row['fleetref']; $fleetmake = $row['fleetmake']; $fleetmodel = $row['fleetmodel']; $fleetyear = $row['fleetyear']; $fleetchassis = $row['fleetchassis']; $fleetberth = $row['fleetberth']; $fleetlayout = $row['fleetlayout']; $fleetlength = $row['fleetlength']; $fleettype = $row['fleettype']; $fleetof = $row['fleetof']; $fleetimage1 = $row['fleetimage1']; $fleetimage2 = $row['fleetimage2']; $fleetimage3 = $row['fleetimage3']; $fleetimage4 = $row['fleetimage4']; $fleetadded = $row['fleetadded']; $fleetengine = $row['fleetengine']; $pricelow = $row['pricelow']; $pricemid = $row['pricemid']; $pricehigh = $row['pricehigh']; $fleetviews = $row['fleetviews']; $query = mysql_query("SELECT * FROM mhhire WHERE `ref` = '$fleetof'"); if(mysql_num_rows($query)==0){ echo "<p>This company does not exsist</p>"; }else{ while($details = mysql_fetch_array($query)){ $company = $details ['company']; $location = $details ['location']; echo "<div class=\"fleet_vehicle\">"; if ($fleetimage1 == "fleet/") { echo "<img src=\"images/no_image.jpg\" alt=\"$fleetmake $fleetmodel\" width=\"100\" height=\"75\" class=\"fleet_thumb\">"; } else { echo "<img src=\"$fleetimage1\" alt=\"$fleetmake $fleetmodel\" width=\"100\" height=\"75\" class=\"fleet_thumb\">"; } echo "<div class=\"fleet_title\">$fleetmake $fleetmodel $fleetyear</div>"; echo "<div class=\"fleet_berth\"><img src=\"images/$fleetberth.gif\" alt=\"$fleetberth berth\"></div>"; echo "<div class=\"fleet_details_in\"><div class=\"fleet_details\">- $fleetberth berth<br />- $fleetlayout<br /></div></div>"; echo "<div class=\"fleet_details_in\"><div class=\"fleet_details\">- $fleetchassis<br />- $fleetengine<br /></div></div>"; echo "<div class=\"fleet_details_in\"><div class=\"fleet_details\">- $fleetlength meters<br />- $fleettype<br /></div></div>"; echo "<div class=\"fleet_options\">From <strong>$company</strong> in <strong>$location</strong> - <a href=\"view_motorhome_for_hire.php?ref=$fleetref\">More info >></a></div>"; echo "</div>"; }} } } ?> Hello all, I've run into a problem with what seems to be a basic script. I want to display two different tables of data, side by side. Each table is built with a while loop, pulling data from an MySQL query. When I try to wrap the first table in a div the result is a div that appears empty when there is really a table with 60 rows of data I expect it to wrap around. I can't get this to work, I've tried to insert the div tag in many places to no avail. Also, I wanted to add some blank space at the bottom of the page so that there was room between the end of the table and the actual bottom of the page. I tried adding some <br />'s at the end of the code but that didn't work. I guess I'm confused because the code is acting as if the 60 rows of table data isn't there. When I tried to add my page layout around the script (as includes at the top and bottom of the script) the layout acts as if the table isn't there, either. That is to say that my "header" and "footer" appear bunched up at the top of the page as if there wasn't content on the screen. Hopefully someone can help! Thanks. Code: [Select] <?php echo "<br /> <a href='index.php'> Back Home </a> <br /> <br />"; // -------------------------- Connect to DB include ('connect_script.php'); // ------------------------------ Color variable for alternating table colors $color = 1; // ------------------------- Query Parameters $select = "SELECT (number) AS id, (first_name) AS fn, (last_name) AS ln, (position) AS position FROM table WHERE position = 'X' "; $get = @mysqli_query ($dbc, $select); // ------------------------- Run Query if ($get) { // ------------------------Start table echo " <div style='border-style: solid;'> <table align='left' border='1'> <tr> <td>People</td> </tr> <tr> <td>ID</td><td>First Name</td><td>Last Name</td><td>Position</td> </tr>"; // ------------------------ Retrieve People while ($row = mysqli_fetch_array($get, MYSQLI_ASSOC)) if ($color==1) {echo ' <tr bgcolor= #47EA7D> <td>' . $row['id'] . '</td><td>' . $row['fn'] . '</td><td>' . $row['ln'] . '</td><td>' . $row['position'] . '</td> </tr>'; $color = '2';} else {echo ' <tr bgcolor= #A4C8B0> <td>' . $row['id'] . '</td><td>' . $row['fn'] . '</td><td>' . $row['ln'] . '</td><td>' . $row['position'] . '</td> </tr> '; $color= '1';} // ----------------------- Close table echo "</div> </table>"; mysqli_free_result ($get); } // -------------------- IF ERROR WITH QUERY else {echo "Didn't connect";} // ---------------------- Spaces --> This is the code that doesn't appear to affect the space at the bottom of the table echo "<br /> <br /> <br />"; ?> I have loaded two similar xml files by simplexml_load_file, and I want to merge them. They have similar structure and I want to put them into a single xml. As a matter of fact, I have parse two similar xml files with foreach, and now I want to put them together and use one foreach for the merged xml. I hope to find a function like array_merge() How can I merge the array, but I keep in mind that I only need to merge userlocation and the usercity arrays. Current output... Code: [Select] Array ( [0] => Array ( [0] => userlocation [1] => 19 ) [1] => Array ( [0] => credentials [1] => ) [2] => Array ( [0] => specialties [1] => ) [3] => Array ( [0] => usercity [1] => place1 ) ) Desired output... Code: [Select] Array ( [0] => Array ( [0] => userlocation [1] => 19 [2] => usercity [3] => place1 ) [1] => Array ( [0] => credentials [1] => ) [2] => Array ( [0] => specialties [1] => ) ) How can this be done? The array is dynamic. Hi, I'm trying to make my game navigation that involves switching div images to navigate in the game world. It is browser based. The first script, the user clicks on the world map to go to "Teardrop Ocean". The second script lets the user press the "further" button or "back" button to navigate within "Teardrop Ocean". My problem is I'm trying to combine the image map navigation with the "further" and "back" navigation. The problem is, I don't know if it's possible since the first world map script involves javascript. Here is the code, any help greatly appreciated Thanks. Derek This is the code that uses javascript to process a hidden form to use php to output. This is our "world map" link, that should load the "teardrop ocean" image inside the div, which it doesn't do yet here. Code: [Select] <?php $zone=''; if(isset($_POST['checker']) && $_POST['checker'] == 'checked') { echo "it worked !"; $zone="<img src='teardrop.jpg'/>"; } if(isset($_POST['back'])) { $zone=''; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="aradia.php" method="post" name="mapform" id="mapform"> <input type="hidden" name="checker" value="checked" /> <div align="left"> <img src="aradia.jpg" width="256" height="328" border="0" usemap="#Map" /></div> </form> <map name="Map" id="Map"> <area shape="rect" coords="5,176,81,249" href="javascript: void(0);" onclick="javascript: document.getElementById('mapform').submit();" /> </map> <div align="center"><?php echo $zone;?></div> <form action="aradia.php" method="post" > <input type = "submit" name="back" value="back" /></form> </body> </html> and here is the "Teardrop ocean" navigation, which uses php to navigate forward and backwards in the zone, but can't go back to the world map, or there is no way to yet. Code: [Select] /////////////////////////////GAME NAVIGATION AND MONSTER SEARCH CODE NOT FINISHED////////////////////////////////// if(( !isset($_SESSION['current_background']) && !isset($_SESSION['currentMonster'])) OR (! $_POST)) { $_SESSION['current_monster'] = 0; $_SESSION['current_background'] = 0; } if (!isset($_SESSION['background']) && !isset($_SESSION['monster'])) { $_SESSION['background'] = array ( "<img src='sundragon_environments/ocean/ocean1_FRAME.jpg'/>", "<img src='sundragon_environments/ocean/ocean1_FRAME2.jpg'/>", "<img src='sundragon_environments/ocean/ocean1_FRAME3.jpg'/>", "<img src='sundragon_environments/ocean/ocean1_FRAME4.jpg'/>", "<img src='sundragon_environments/ocean/ocean1_FRAME5.jpg'/>" ); $_SESSION['monster'] = array ( "<img src='sundragon_monsters_source/water/goldfish/goldfish.png'/>", "<img src='sundragon_monsters_source/water/eel/eel_transp_FRAME.png '/>", "<img src='sundragon_monsters_source/water/shark/shark_transp_FRAME.png'/>", "<img src='sundragon_monsters_source/water/octalisk/octalisk_transp_FRAME.png'/>", "<img src='sundragon_monsters_source/water/teardrop_ocean_protector/teardrop_ocean_protector.png'/>" ); } if(!isset($_SESSION['current_background']) && !isset($_SESSION['current_monster'])) { $_SESSION['current_monster']=0; $_SESSION['current_background'] = 0; } if(isset($_POST['further'])) { $_SESSION['current_monster'] = isset($_SESSION['monster'][$_SESSION['current_monster'] + 1]) ? ($_SESSION['current_monster'] + 1) : 0; $_SESSION['current_background'] = isset($_SESSION['background'][$_SESSION['current_background'] + 1]) ? ($_SESSION['current_background'] + 1) : 0; } elseif(isset($_POST['back'])) { $_SESSION['current_monster'] = isset($_SESSION['monster'][$_SESSION['current_monster'] - 1]) ? ($_SESSION['current_monster'] - 1) : count($_SESSION['monster'])-1; $_SESSION['current_background'] = isset($_SESSION['background'][$_SESSION['current_background'] - 1]) ? ($_SESSION['current_background'] - 1) : count($_SESSION['background'])-1; } $currentBackground=$_SESSION['background'][$_SESSION['current_background']]; $currentMonster=$_SESSION['monster'][$_SESSION['current_monster']]; and I echo out $currentBackground and $currentMonster in the main game div. i have this list of arrays Code: [Select] Array ( [0] => LeanBiz ) Array ( [0] => Boutique ) Array ( [0] => Feather ) Array ( [0] => Aggregate )i want to create one single array containing the values from x arrays. Hello, I've created a PHP file to merge XML files by ReferenceID(product_print_id) but i don't get the result that i want. I think i must use cloneNode and DOMNode::insertBefore but I think i'm lost. The first file is prodInfo.xml: <?xml version="1.0" encoding="utf-8"?> <PRODUCTINFORMATION> <PRODUCTS> <PRODUCT> <PRODUCT_NUMBER>53-03</PRODUCT_NUMBER> <PRODUCT_PRINT_ID>42</PRODUCT_PRINT_ID> <PRODUCT_NAME>ProductFirst</PRODUCT_NAME> <COLOR_CODE>03</COLOR_CODE> </PRODUCT> </PRODUCTS> </PRODUCTINFORMATION> and the second file is printInfo.xml: <?xml version="1.0" encoding="utf-8"?> <PRINTINGINFORMATION> <PRODUCTS> <PRODUCT> <PRODUCT_PRINT_ID>42</PRODUCT_PRINT_ID> <PRINTING_POSITIONS> <PRINTING_POSITION> <ID>TOP BOX</ID> <PRINTING_TECHNIQUE> <ID>DL</ID> </PRINTING_TECHNIQUE> <PRINTING_TECHNIQUE> <ID>L2</ID> </PRINTING_TECHNIQUE> <PRINTING_TECHNIQUE> <ID>P4</ID> </PRINTING_TECHNIQUE> </PRINTING_POSITION> </PRINTING_POSITIONS> </PRODUCT> </PRODUCTS> </PRINTINGINFORMATION> The php file i created is the following: <?php header ("Content-Type:text/xml"); $target = new DOMDocument(); $target->preserveWhiteSpace = FALSE; $target->load('prodInfo.xml'); $targetXpath = new DOMXpath($target); $source = new DOMDocument(); $source->load('printInfo.xml'); $sourceXpath = new DOMXpath($source); foreach ($targetXpath->evaluate('//PRODUCT') as $PRODUCTNode) { $PRODUCT_PRINT_ID = $targetXpath->evaluate('string(PRODUCT_PRINT_ID)', $PRODUCTNode); foreach ($sourceXpath->evaluate('//PRODUCT[PRODUCT_PRINT_ID="'.$PRODUCT_PRINT_ID.'"]/*[not(self::PRODUCT_PRINT_ID)]') as $node) { $PRODUCTNode->appendChild( $target->importNode($node, TRUE) ); } } $target->formatOutput = TRUE; echo $target->saveXml(); ?> The output/result i get is this: <?xml version="1.0" encoding="utf-8"?> <PRODUCTINFORMATION> <PRODUCTS> <PRODUCT> <PRODUCT_NUMBER>53-03</PRODUCT_NUMBER> <PRODUCT_PRINT_ID>42</PRODUCT_PRINT_ID> <PRODUCT_NAME>ProductFirst</PRODUCT_NAME> <COLOR_CODE>03</COLOR_CODE> <PRINTING_POSITIONS> <PRINTING_POSITION> <ID>TOP BOX</ID> <PRINTING_TECHNIQUE> <ID>DL</ID> </PRINTING_TECHNIQUE> <PRINTING_TECHNIQUE> <ID>L2</ID> </PRINTING_TECHNIQUE> <PRINTING_TECHNIQUE> <ID>P4</ID> </PRINTING_TECHNIQUE> </PRINTING_POSITION> </PRINTING_POSITIONS> </PRODUCT> </PRODUCTS> </PRODUCTINFORMATION> But what i want to achieve is this: <?xml version="1.0" encoding="utf-8"?> <PRODUCTINFORMATION> <PRODUCTS> <PRODUCT> <PRODUCT_NUMBER>53-03</PRODUCT_NUMBER> <PRODUCT_PRINT_ID>42</PRODUCT_PRINT_ID> <PRODUCT_NAME>ProductFirst</PRODUCT_NAME> <PRINTING_POSITIONS> <PRINTING_POSITION> <ID>TOP BOX</ID> <PRINTING_TECHNIQUE> <ID>DL</ID> </PRINTING_TECHNIQUE> <COLOR_CODE>03</COLOR_CODE> </PRINTING_POSITION> <PRINTING_POSITION> <ID>TOP BOX</ID> <PRINTING_TECHNIQUE> <ID>L2</ID> </PRINTING_TECHNIQUE> <COLOR_CODE>03</COLOR_CODE> </PRINTING_POSITION> <PRINTING_POSITION> <ID>TOP BOX</ID> <PRINTING_TECHNIQUE> <ID>P4</ID> </PRINTING_TECHNIQUE> <COLOR_CODE>03</COLOR_CODE> </PRINTING_POSITION> </PRINTING_POSITIONS> </PRODUCT> </PRODUCTS> </PRODUCTINFORMATION> So as you can see i want to repeat the field PRINTING POSITION ID for every PRINTING TECHNIQUE and also i want to repeat the field COLOR CODE for every PRINTING POSITION. Anyone can help me with this? Thanks in advance. Whats the array function to merge two or more similar patterns in a single array. $a = array('red','pink','red','green','blue'); Basically i need to combine "red" so the output will be red, pink, green, blue i want to preserve the numeric keys. When i print the array this is the result Code: [Select] Array ( [0] => one [1] => two [2] => three ) it should be Code: [Select] Array ( [0] => two [1] => one [2] => three ) Code: [Select] $test1[2] = "one"; $test2[1] = "two"; $test2[3] = "three"; $test = array_merge($test1,$test2); print_r($test); How do i solve this? Hi. I have two arrays: $one = array('a', 'b', 'c'); $two = array('123', '456', '789'); My desired output is: $output = array('123a', '123b', '123c', '456a', '456b', '456c', '789a', '789b', '789c' ) How can this be achieved, I have looked into functions such as array_merge() but it doesnt seem to do the job. Help greatly appreciated! I have a task that seems to be complex.
Short Description: currently users of the application I am hired to develop have two steps to do when using the app:
1. Select a Product Line (A, B, C, D)
2. Select input parameters for that product line - all product lines have simlar "Main" input parameters, but also each line has its own special features that can be selected.
3. Selections for that product line are shown - the result is a long table or options for that particular product line. Things like price, discounts, product specifications, etc.
What the users want now is this:
1. Select input parameters (not sure how to handle individual product lines special parameters yet)
2. Selections for all product lines are shown
The code base is legacy code, with code thrown around everywhere. One idea me and my coworkers have been considering is a complete rewrite, since it will help us with writing tighter code, and do what the customer wants. But that will also take time, and there is no spec. The spec is in the code mess.
Another one is I am considering now is a "merge". Somehow merge the product lines, since we have the separate product modules (A, B, C, D), there must be a way to consider maybe extending one to include the others, or somehow get me to the end result -- allow users to see selections for all product lines.
Do you have any experience, any suggestions on how to do this? I know this needs details, and details are in my code that you don't see, and most likely won't have the time to read and understand anyway.
But I am looking for any ideas or encouragement though that may help. And my question is -- is there any kind of procedure or technique or something to deal with the problem I am facing -- merging several separate yet similar modules into one single merged module. How do I approach this, what are some things that could help, etc. That's what I'm looking for.
The queries merge ok and results are correct except I get a notice: "Notice: Use of undefined constant UNION - assumed 'UNION' in...."
But is UNION a constant or is the context wrong?
$query = $query1." ".UNION." ".$query2; $result = mysqli_query($dbcon, $query) or die('Error getting data'); $num_rows = mysqli_num_rows($result); I am using pieces of an array like this: $data['0']; $data['2']; $data['3']; and so on...I think up to around $data['70']; I need to take the values of $data['29'] through $data['64'] and combine them. (stumped) On top of that I have to comma separate those now combined values (stumped). Actuall Code: $handle = fopen("test.csv", "r"); while (($data = fgetcsv($handle, 5000, ",")) !== FALSE){ $needed = $data['29'] .", ". $data['30'] .", ".$data['31']; // ALL THE WAY TO $data['65'] } I know how to do it the long way, could someone help me shorten my work? Thank you for your help. For example: class People{ var $them = array(); function groupPeople(){ foreach($this->them as $him){ echo $him.", "; } } } $people = new People; $people->them = array('Harry','Todd'); $people->them = array('Tom','Jerry'); $people->groupPeople(); // result: Tom, Jerry, I think this code is working. However, I need to merge those array above, array('Harry','Todd') and array('Tom','Jerry') So I can get array('Harry','Todd','Tom','Jerry') and a list of names as a result. Maybe I should use array_merge, but how? A little help would be appreciated. Thank you in advanced, ayok I have two arrays, as follows: $array1 = (1, 2, 3); $array2 = (4, 5, 6); Is there a function to combine the two without having to do a loop? I'd like to create: $array3 = (1, 2, 3, 4, 5, 6); I have a successful select query, where I'm looping and building a row for getting parameters which works correctly while ($row = $orderDetailCheck->fetch(PDO::FETCH_ASSOC)) {
$params = [ } My issue now is that, for each row, I need to perform two merges because the data from that select is going to be split into two tables in db2. Some values are truly split between the tables but some values are shared between the two. I'm not sure the best way to perform these two merges because if the first one (products table) inserts, then it creates an ID that I need as a foreign key basically, to insert into the orders table. So on insert I need to grab that newly created ID and use it for ```product_id``` in the second merge. If the first merge performs the update when matched, then I need to grab the existing ID for that record so that I can update the proper record in the orders table. My two merge statements:
/*products table*/
:GROUP,
)
AS S(GROUP,DTL12,DTL13,CUSTNM,SELLINGN,COUNT_PLMN_1,LAST_DATE)
WHEN MATCHED
WHEN NOT MATCHED
/*ORDERS Table*/
/*need foreign key, which is id from products table*/
AS S(PRODUCT_ID,quantity_ordered,LAST_DATE,invoice_number)
WHEN MATCHED
WHEN NOT MATCHED Examples:
INVOICE | CUSTNM | SELLINGNUM | GROUP | DTL12 | DTL13 | QUANTITY | COUNT_PLMN_1 | LAST_DATE
products
ID | GROUP | DTL12 | DTL13 | CUSTNM | SELLINGNUM | COUNT_PLMN_1 | LAST_DATE
ORDERS
PRODUCT_ID | QUANTITY_ORDERED | LAST_DATE | INVOICE
INVOICE | CUSTNM | SELLINGNUM | GROUP | DTL12 | DTL13 | QUANTITY | COUNT_PLMN_1 | LAST_DATE
products
ID | GROUP | DTL12 | DTL13 | CUSTNM | SELLINGNUM | COUNT_PLMN_1 | LAST_DATE and update orders like so: ORDERS
PRODUCT_ID | QUANTITY_ORDERED | LAST_DATE | INVOICE I guess the main question is: How can I get the ID of a record from the products table (whether it's an existing match OR newly created in the merge) and once I get it, how can I use it for the 2nd merge? Hi i made this script for uploading files and it works correctly... <div><h2>Uploaden</h2> <form enctype="multipart/form-data" action="upload.php" method="POST"> Kies een bestand om te uploaden: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Uploaden" /> </form> But i have a seperate file wich is called upload.php. <?php $target_path = "images/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } ?> Is there any way i can combine those in one php file and so it will give the output on the same screen? If i combine them like below it works but the first time the page loads i get an error message... <div><h2>Uploaden</h2> <form enctype="multipart/form-data" action="index.php" method="POST"> Kies een bestand om te uploaden: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Uploaden" /> </form> <?php $target_path = "images/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } ?> And this is the error message.... Notice: Undefined index: uploadedfile in C:\wamp\www\test\index.php on line 59 Notice: Undefined index: uploadedfile in C:\wamp\www\test\index.php on line 61 But when i upload a file everything is ok... I'm using a upload class that works with $_FILES, but have a couple of reasons to need the content of php://input: 1) When submitting PDF forms as a complete form, the form is available in php://input. 2) An ajax uploader I'd like to use submits the file making it only available in php://input. I know I could use an if statement to check $_FILES else php://input, but I'm concerned about security, and being able to identify the filetype, get the size, etc. I'm skipping over some other details, because I need to leave in 5 minutes. I've not seen any classes that merge the two ( $_FILES and php://input ), and really haven't seen any that are specifically for php://input. Can anyone offer advice or point me in the right direction? I'd like to merge the following function into my main download page but can't figure out how to do it. I've modified the main download page to do the actual downloads but how to manage making the database entries for each download is the problem. I guess I could use a case statement at the end of download.php to set $l_filename then run the pdo sql code. mydownloader.php - Currently located in download directory <?php $php_scripts = '../../php/'; require $php_scripts . 'PDO_Connection_Select.php'; require $php_scripts . 'GetUserIpAddr.php'; function mydloader($l_filename=NULL) { $ip = GetUserIpAddr(); if (!$pdo = PDOConnect("foxclone_data")) { exit; } */ if( isset( $l_filename ) ) { header('Content-Type: octet-stream'); header("Content-Disposition: attachment; filename={$l_filename}"); header('Pragma: no-cache'); header('Expires: 0'); readfile($l_filename); /* $ext = pathinfo($l_filename, PATHINFO_EXTENSION); $stmt = $pdo->prepare("INSERT INTO download (address, filename,ip_address) VALUES (?, ?, inet_aton('$ip'))"); $stmt->execute([$ip, $ext]) ; $test = $pdo->query("SELECT lookup.id FROM lookup WHERE inet_aton('$ip') >= lookup.ipstart AND inet_aton('$ip') <= lookup.ipend"); $ref = $test->fetchColumn(); $ref = intval($ref); $stmt = $pdo->prepare("UPDATE download SET lookup_id = '$ref' WHERE address = '$ip'"); $stmt->execute() ; } else { echo "isset failed"; } } mydloader($_GET["f"]); exit;
<?PHP require_once("header.php"); ?> </head> <body> <?PHP require_once("navbar.php"); ?> <!--==================================================================== Download =======================================================================--> <?php $php_scripts = '../php/'; require $php_scripts . 'PDO_Connection_Select.php'; if (!$pdo = PDOConnect("foxclone_data")) { exit; } $test = $pdo->query("SELECT filename FROM files WHERE id =1"); $isoname = $test->fetchColumn(); $test = $pdo->query("SELECT md5 FROM files WHERE id =1"); $md5file = $test->fetchColumn(); $test = $pdo->query("SELECT filename FROM files WHERE id =2"); $pdfname = $test->fetchColumn(); $test = $pdo->query("SELECT filename FROM files WHERE id =3"); $debname = $test->fetchColumn(); $test = $pdo->query("SELECT md5 FROM files WHERE id =3"); $debmd5 = $test->fetchColumn(); $test = $pdo->query("SELECT filename FROM files WHERE id =4"); $srcname = $test->fetchColumn(); $test = $pdo->query("SELECT md5 FROM files WHERE id =4"); $srcmd5 = $test->fetchColumn(); $test = $pdo->query("SELECT filename FROM files WHERE id =5"); $debfile = $test->fetchColumn(); ?> <div class="head__h1">FoxClone Download Page</div> <div class ="download"> <div class="down__row"> <div class="down__column" style="background-color:#ddd;"> <div class="part__head">Get the "<?php echo "{$isoname}";?>" file (approx. 660MB)</div><br> <a href="download/{$isoname}";?>"><center><img src="images/download.png" style="height:44px; width:144px;" alt="download iso"> </center></a> <br /> <div class="part__head">The MD5sum is: <?php echo "{$md5file}";?> </div> <br/> <hr> <div class="part__head">Read or Download the Installation and Use Instructions </div><br> <a href="<?php echo "download/{$pdfname}";?>"><center><img src="images/download.png" style="height:44px; width:144px;" alt="download manual"></center></a><br> <hr> <div class="part__head">How To Install To A USB/CD</div> <div class="down__text">1. Download the iso file <br /> 2.<span class="tab">a. If burning to a USB stick use the USB image writer that comes with your distribution. </span> <br /> <span class="tab3">b. If burning to a CD, there are many Linux utilities, xfburn is one of the simplest. Install from your software manager/centre if not installed.</span> </div> <hr> <div class="part__head">How To Boot The USB/CD</div> <div class="down__text">At the manufacturer’s splash screen, press the key to get into the boot menu. This key varies across PCs, as an example for a Lenovo Thinkpad it is F12. Consult your user manual to find out what the key is or google. Do not confuse the boot menu with the boot priority order settings in BIOS. The boot menu is a one time selection for the device to use to boot the PC. It overrides the normal boot priority order. The next time you boot, the PC will revert to the normal boot order. Virtually all BIOSs support this feature, they just do it differently. </div> </div> <div class="down__column" style="background-color:#ddd;"> <div class="part__head">Get the "<?php echo "{$debname}";?>" file (approx. 7MB) </div><br> <a href="download/{$debname}";?>"><center><img src="images/download.png" style="height:44px; width:144px;" alt="download deb file"> </center></center></a> <br /> <div class="part__head">The MD5sum is: <?php echo "{$debmd5}";?> </div> <div class="down__redtext"><br>WARNING - FOR EXPERT USE ONLY !!!</div> <div class="down__text"><br>This .deb file is designed to be installed on a large USB drive, typically 1TB or greater, that already has an operating system installed and is intended as a backup drive.<b> For more information <a href="/download/deb_file.pdf" style="color:#ff0099">Click Here.</a></b></h3> </div> <hr> <div class="part__head">Get the "<?php echo "{$srcname}";?>" Source file (approx. 6MB) </div><br> <a href="download/{$srcname}";?>"><center><img src="images/download.png" style="height:44px; width:144px;" alt=""></center> </a> <br> <div class="part__head">The MD5sum is: <?php echo "{$srcmd5}";?> </div> <div class="down__text"><br />This contains the files used to build Foxclone itself. It is provided to meet the terms of the GNU General Public License.</div> </div> </div> </div> <?PHP require_once("footer.php"); ?>
|