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

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

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

Post 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
Last edited by Nullig on Thu Jul 10, 2008 11:09 pm, edited 1 time in total.
User avatar
jtcreate
Forum Members
Forum Members
Posts: 168
Joined: Wed Mar 21, 2007 11:01 am

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

Post by jtcreate »

Nullig,

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

Enjoy your day. And thanks again...

Jeff T.
Mmmmm... Tasty.
Post Reply

Return to “CMSMS Core”