Jump to content

kristo5747

Members
  • Posts

    58
  • Joined

  • Last visited

    Never

Contact Methods

  • Website URL
    http://www.directv.com
  • Yahoo
    abonnemaison

Profile Information

  • Gender
    Male
  • Location
    Los Angeles

kristo5747's Achievements

Member

Member (2/5)

0

Reputation

  1. Linux Red Hat (Sorry I forgot to mention that). Further investigating shows PHP was not compiled on my server with ZIP support. The configure command section of PhpInfo() does not show the --enable-zip option. PECL is not installed either so I cannot workaround my problem with pecl install zip either. I am not sure what to do next....
  2. Hello, I am trying to implement a simple script that ZIPs up a text file. The problem is that I don't think the ZIPArchive is available on my server. Here is an example of my code: <?php $zip = new ZipArchive(); $filename = "./PJR.v2.zip"; if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) { exit("cannot open <$filename>\n"); } if ($handle = opendir('WORKDIR')) { while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { $zip->addFile($entry); } } closedir($handle); } $zip->close(); ?> When I run it from the command line, I get PHP Fatal error: Class 'ZipArchive' not found in /users/albert/zip_POC.v2.php on line 2 This is the version info on my server: php -v PHP 5.1.6 (cli) (built: Nov 12 2008 11:22:53) Copyright (c) 1997-2006 The PHP Group Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies Is there a way that I can install that class even though I am not the 'root' user??
  3. It was an encoding problem. Tried the following: ob_start(); // Starts output buffering. readfile($fileName); // "Outputs" the file. $content = ob_get_clean(); // Grabs the output and assigns it to a variable. print base64_encode($content); // Encodes and prints the content to the browser. Took care of it.
  4. I wrote a very simple web form that allows my user to view text files from within their Internet browser. I implemented a feature whereby the text files returned by the search are compressed into a ZIP. Here's my code function getFiles() { $result = null; $ZIPresult = null; if (empty($_POST['DBRIDs'])) { return null; } $mydir = MYDIR; $dir = opendir($mydir); $DBRIDs = $_POST['DBRIDs']; $getfilename = mysql_query("select filename from search_table where rid in (" . $DBRIDs . ")") or die(mysql_error()); while ($row = mysql_fetch_array($getfilename)) { $filename = $row['filename']; $result .= '<tr><td><a href="' . basename($mydir) . '/' . $filename . '" target="_blank">' . $filename . '</a></td></tr>'; $ZIPresult .= basename($mydir) . '/' . $filename; } if ($result) { $result = "<table><tbody><tr><td>Search Results.</td></tr> $result</table>"; shell_exec("zip -9 SearchResult.zip ". $ZIPresult ." > /dev/null "); $fileName = 'SearchResult.zip'; header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Transfer-Encoding: binary"); header('Content-type: application/zip'); header("Content-length: " . filesize($fileName)); header('Content-Disposition: attachment; filename="' . $fileName . '"'); readfile($fileName); } return $result; } It works great If I download the ZIP file from the server using FTP (for example) but I force the download from the page header, the ZIP is corrupted. What am I missing? Thanks for your input. **PS: The new ZipArchive() library/class is not available on our production environment so I chose to use the Unix utility ZIP instead.**
  5. That was it . I can now ZIP multiple files. Thanks a million!
  6. I wrote a very simple web form that allows my user to view text files from within their Internet browser. Occasionally, the search criteria entered returns more than one file. So I want to implement a feature whereby the text files returned by the search are compressed into a ZIP. I got a prototype working but it only compresses the first file. The second or third files are ignored. Here's my code <HTML><body><form name="myform" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <fieldset><label for="DBRIDs">RIDs</label><input type="text" id="DBRIDs" name="DBRIDs" > </fieldset></form></body></HTML> <?php function check_search() { if (isset($_POST['submit'])) {if (!empty($_POST['DBRIDs'])) { $results = getFiles(); } } else $errors = "Please enter something before you hit SUBMIT."; return Array($results, $errors); } function getFiles() { $result = null; $ZIPresult = null; if (empty($_POST['DBRIDs'])) { return null; } $mydir = MYDIR; $dir = opendir($mydir); $DBRIDs = $_POST['DBRIDs']; $getfilename = mysql_query("select filename from search_table where rid in (" . $DBRIDs . ")") or die(mysql_error()); while ($row = mysql_fetch_array($getfilename)) { $filename = $row['filename']; $result .= '<tr><td><a href="' . basename($mydir) . '/' . $filename . '" target="_blank">' . $filename . '</a></td></tr>'; $ZIPresult .= basename($mydir) . '/' . $filename; } if ($result) { $result = "<table><tbody><tr><td>Search Results.</td></tr> $result</table>"; shell_exec("zip -9 SearchResult.zip ". $ZIPresult ." > /dev/null "); } return $result; } The hyperlinks pointing to the file(s) are generated just fine. The ZIP file however only contains the first file listed in the results. How can I get the ZIP file to capture ALL the files returned?? Thanks for your input. **PS: The new ZipArchive() library/class is not available on our production environment so I chose to use the Unix utility ZIP instead.**
  7. Thanks for your help. I think i need to rework the whole flow of the app. Thanks for taking the time.
  8. **Disclaimer: It's been a while since I last wrote any code. The quality of my code is likely to be sub-par. You've been warned.** Greetings. I am coding a basic form that uses a SELECT list I populate from my database. However, my user needs the form to be dynamic and wants to be able to select either `MasterTable1` or `MasterTable2` or `MasterTable3`... Instead of hardcoding the table name for the database query that populates the SELECT list, I attempted to implement a basic Ajax action (used example from w3schools)...and that's when I lost my sanity... I can output `<div id='txtHint'></div>` in my page and it shows the correct table name that was picked. But how do I pass the correct table name to my query that will populate my SELECT list??? I tried <select name="DBFilename" id="DBFilename" size="0"> <option value="">Select Filename</option> <?php $sql="select distinct filename from "."<div id='txtHint'></div>"; $result = mysql_query($sql); while ($row = mysql_fetch_array($result)){ ?> <option value="<?php echo $row['filename']; ?>"><?php echo $row['filename']; ?></option> <?php } ?> </select> But to no avail. This is confusing since I can do this... ... document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","gettable.php?q="+str,true); xmlhttp.send(); } </script></head> <body><form><select name="SrcTbl" id="SrcTbl" size="0" onchange="showTable(this.value)"> <option value="">Select Data Table</option> <option value=""> </option> <option value="MasterTable1">up to 31 days old</option> <option value="MasterTable2">62 days old</option> </select> </form><br /><div id="txtHint"><select name="tabList"><option></option></select> </div> </body></html> And the name of my table will be displayed in the SELECT list 'tablist'. That <div> supposed to end up being a table name that is returned by the Ajax script. How do I pass the correct table name to my query that will populate my SELECT list? Thanks!! Form code in pastebin.com
  9. Complete re-write here => http://pastebin.com/raw.php?i=qi5F7X2e There are several problems with my form. a) Neither one of my SELECT lists are ever empty. b) I never check for return the values from my functions. This one is working. Thanks for taking the time.
  10. Ignore my previous posts. I did not fix all typos. It's working now.Thank you!! It's working now but it seemingly introduced a new problem: I can't seem to do more than one search at a time. The result shows up again and again. I am using Firefox 6.0 on Ubuntu.
  11. I tried your code but to no avail. The first SELECT works fine. The second SELECT is never submitted.
  12. filename site script station result stbmodel rid testdate
  13. I am sure there better ways to do that...all I want to do is provide a URL to the file located on the server for the file selected from the list. If you have better suggestion, I am all ears.
  14. Added the source of what is created to a pastebin: http://pastebin.com/raw.php?i=mjxkVEmW
  15. **Disclaimer: It's been a while since I last wrote any code. The quality of my code is likely to be sub-par. You've been warned.** I have a basic form that's meant to search flat files on our server. The "search engine" I created as two select lists: one for the file names and one for the customer site files come from. For a reason I can't figure out, whatever option I select from the second select list is never captured when I hit Submit. However, whatever option I select from the first select list is always captured. What am I missing? I am sure it's starting right at me.... Any hints welcome. Thank you. Here's my code: <HTML> <head><title>SEARCH TOOL - PROTOTYPE</title></head> <body><h1>SEARCH TOOL - PROTOTYPE</h1> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <fieldset> <legend>Filename (one item)</legend><select name="DBFilename" id="DBFilename" size="0"> <?php $con = mysql_connect("localhost", "user", "pass"); if (!$con) { die('Could not connect: ' . mysql_error());} mysql_select_db("dev", $con) or die(mysql_error()); $result = mysql_query("select distinct filename from search_test"); while ($row = mysql_fetch_array($result)) { ?> <option value="<?php echo $row['filename']; ?>"><?php echo $row['filename']; ?></option> <?php } mysql_close($con); ?> </select></fieldset> <fieldset> <legend>Site (one item)</legend><select name="DBSite" id="DBSite"> <?php $con = mysql_connect("localhost", "user", "pass"); if (!$con) { die('Could not connect: ' . mysql_error());} mysql_select_db("dev", $con) or die(mysql_error()); $result = mysql_query("select distinct site from search_test"); while ($row = mysql_fetch_array($result)) { ?> <option value="<?php echo $row['site']; ?>"><?php echo $row['site']; ?></option> <?php } mysql_close($con); ?> </select></fieldset> <input type="submit" name="submit" value="submit" > <input type="button" value="Reset Form" onClick="this.form.reset();return false;" /> </form> </body> </HTML> <?php if (isset($_POST['submit'])) { if (!empty($_POST['DBFilename'])) {doFileSearch();} elseif (!empty($_POST['DBSite'])) {doSite();} } function doFileSearch() { $mydir = $_SERVER['DOCUMENT_ROOT'] . "/filedepot"; $dir = opendir($mydir); $DBFilename = $_POST['DBFilename']; $con = mysql_connect("localhost", "user", "pass"); if (!$con) {die('Could not connect: ' . mysql_error());} mysql_select_db("dev", $con) or die("Couldn't select the database."); $getfilename = mysql_query("select filename from search_test where filename='" . $DBFilename . "'") or die(mysql_error()); echo "<table><tbody><tr><td>Results.</td></tr>"; while ($row = mysql_fetch_array($getfilename)) { $filename = $row['filename']; echo '<tr><td><a href="' . basename($mydir) . '/' . $filename . '" target="_blank">' . $filename . '</a></td></tr>'; } echo "</table></body>"; } function doSite() { $mydir = $_SERVER['DOCUMENT_ROOT'] . "/filedepot"; $dir = opendir($mydir); $DBSite = $_POST['DBSite']; $con = mysql_connect("localhost", "user", "pass"); if (!$con) {die('Could not connect: ' . mysql_error());} mysql_select_db("dev", $con) or die("Couldn't select the database."); $getfilename = mysql_query("select distinct filename from search_test where site='" . $DBSite . "'") or die(mysql_error()); echo "<table><tbody><tr><td>Results.</td></tr>"; while ($row = mysql_fetch_array($getfilename)) { $filename = $row['filename']; echo '<tr><td><a href="' . basename($mydir) . '/' . $filename . '" target="_blank">' . $filename . '</a></td></tr>'; } echo "</table></body>"; } ?>
×
×
  • 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.