Page 2 of 2

Re: View Page, No Download | View Page, Download

Posted: Thu Jul 10, 2008 8:06 pm
by Nullig
Ok, this assumes a document naming convention of:

- Where there are 2 documents, they are named ###-Product Name-A.pdf and ###-Product Name-B.pdf
- Where there is only 1 document, it is named ###-Product Name-anything else.pdf or ###-Product Name.pdf

and no subdirectories under /uploads/products/.

Code: Select all

global $gCms;
$dir = "uploads/products/";

echo "<table>\n";
echo "<thead>\n";
echo "<tr>";
echo "<th>Product Number</th>";
echo "<th>Product Name</th>";
echo "<th>Document One</th>";
echo "<th>Document Two</th>";
echo "</tr>\n";
echo "</thead>\n";
echo "<tbody>\n";

if ($handle = opendir($dir)) { 

   while (false !== ($file = readdir($handle))) {
      if ($file != "." && $file != "..") { 
         $fileList[] = $file;

      }
   }

   sort ($fileList); 
   reset ($fileList);

   while (list ($key, $val) = each ($fileList)) {

      $products1 = explode(".", $val);
      $products2 = explode("-", $products1[0]);

      if ($products2[2]=="A") {

         echo "<tr><td>$products2[0]</td>";
         echo "<td>$products2[1]</td>";

         if ($params['linked']=='true') {
            echo "<td><a href='$dir$val' target='_blank'>$val</a></td>";
         } else {
            echo "<td>$val</td>";
         }

      } elseif ($products2[2]=="B") {

         if ($params['linked']=='true') {
            echo "<td><a href='$dir$val' target='_blank'>$val</a></td></tr>\n";
         } else {
            echo "<td>$val</td></tr>\n";
         }

      } else {

         echo "<tr><td>$products2[0]</td>";
         echo "<td>$products2[1]</td>";

         if ($params['linked']=='true') {
            echo "<td><a href='$dir$val' target='_blank'>$val</a></td></tr>\n";
         } else {
            echo "<td>$val</td></tr>\n";
         }

      }

   }

   closedir($handle);

}
echo "</tbody>\n";
echo "</table>\n";
if ($params['linked']=='false') {
   echo "<p>You must be logged in to download these documents.</p>";
}
I'm sure there are far more elegant ways to do this, but for a quick and dirty fix...

Nullig

Re: [SOLVED] View Page, No Download | View Page, Download

Posted: Fri Jul 11, 2008 11:15 am
by jtcreate
Nullig,

I can't thank you enough. It works great!

Enjoy your day. And thanks again...

Jeff T.